[英]How should I create a class with functions to be shared across multiple application services with aspnetboilerplate?
I have code/common functionality that needs to be re-used in multiple app services (ie say a simple lookup function).我有需要在多个应用程序服务中重复使用的代码/通用功能(例如,一个简单的查找功能)。 I am looking to create a Helper class that isn't really an API, just something for other app services or even the ui mvc controllers to consume.我正在寻找创建一个不是真正 API 的 Helper 类,只是供其他应用程序服务甚至 ui mvc 控制器使用的东西。
I read in the aspnetboilerplate documentation we should not call an app service from another app service which I agree creates a mess.我在 aspnetboilerplate 文档中阅读了我们不应该从另一个应用服务调用应用服务,我同意这会造成混乱。
I know we can implement a custom repository inheriting RepositoryBase within the Entity Framework project with this logic and inject that repository我知道我们可以使用此逻辑在实体框架项目中实现一个自定义存储库继承 RepositoryBase 并注入该存储库
I also know we can create a domain service and put the code in a manager but this is more application logic than domain logic.我也知道我们可以创建一个域服务并将代码放在管理器中,但这更像是应用程序逻辑而不是域逻辑。
What's the best practice for creating a helper class that can be constructor injected into each application service?创建一个可以作为构造函数注入每个应用程序服务的辅助类的最佳实践是什么?
You may be overthinking this.你可能想多了。
What's the best practice for creating a helper class that can be constructor injected into each application service?创建一个可以作为构造函数注入每个应用程序服务的辅助类的最佳实践是什么?
I read in the aspnetboilerplate documentation we should not call an app service from another app service which I agree creates a mess.我在 aspnetboilerplate 文档中阅读了我们不应该从另一个应用服务调用应用服务,我同意这会造成混乱。
Agreed.同意。 However, as you state, this is not a service as such.但是,正如您所说,这不是一项服务。 It is a utility class and you're not going to be calling a web-api to access the class, you'll be calling the methods directly on the injected class.它是一个实用程序类,您不会调用 web-api 来访问该类,您将直接在注入的类上调用方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.