c# - asp.net mvc 和 Controller 服务架构

标签 c# asp.net-mvc architecture

我想让我的架构更好,但我不知道如何解决依赖问题。

我有什么:

  1. CoreService 类库有很多接口(interface) IMail, Ilog, ISession
  2. 在应用程序开始时,我创建了基于IMailIlogISession 的类,并将其传递给 CoreService 类
  3. 具有 CoreService 实例的基本 Controller 类(属性 CoreService Services {get;})
  4. 用户插件使用CoreService接口(interface)

问题: 每次我需要添加新服务时,我都必须编辑应用程序启动,CoreService。理想情况下,我只想为 IMail(或任何其他服务)创建一个类库,然后在 web.config 或应用启动中注册它。

如果有任何对我有帮助的建议或链接,我将不胜感激。

感谢所有用户!

最佳答案

看看Ninject and XML configuration Binding .

我认为这涵盖了您要实现的目标的两个部分。这是依赖注入(inject)以及无需重新编译即可修改配置的能力。

如果您添加 Ninject(或其他 DI 容器 - 例如 Unity)无法为您解析的全新服务,您将需要编辑您的代码。我认为这是无法避免的。

关于c# - asp.net mvc 和 Controller 服务架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7057289/

相关文章:

javascript - 如何从 jquery.tmpl 中解析的 html 中获取子字符串

java - Tomcat 具有同一应用程序的多个实例

perl - 与 Perl 的按需进程间通信

C# 套接字 : Client Mishandle 'a' as the Client's id

c# - 使用 C# SDK 的 Facebook Like 功能

C# 命名空间/文件夹 : when is getting too organized/creating too many namespaces not right?

c# - ASP.NET WindowsAuthentication 自定义 401 未授权错误页面

c# - 带有 ViewModel 参数的 WPF 转换器

c# - asp.net MVC "Action Method"是否可以在不在参数上声明其特定类型的情况下接收 JSON?如果是这样,如何?

architecture - 微服务版本控制