How does ASP.NET 5 inject startup's dependencies?

I'm studying ASP.NET 5 documentation (It's great and better than the old one.) I understand that ASP.NET 5 includes a simple built-in inversion of control (IoC) container that supports constructor injection by default. As far as I know, configuring services and dependencies are done inside ConfigureServices() method.

The ConfigureServices() method is called after StartUp method.

So my question is : how does ASP.NET 5 internally inject Startup's dependencies?

I'd like to know that because if I want to inject another dependency, for example IFooEnviroment how can I do that?


The logic for this lives in the Hosting layer of ASP.NET 5:

  • the Startup type is determined
  • the hosting layer registers the required runtime services in the IServiceCollection
  • An internal service provider is build
  • an instance of the Startup class is created
  • You can of course register your own services in ConfigureServices . But they won't be available in the constructor as you already figured. There is no way to add your own services to the runtime services. This makes sense because there should be a difference between runtime services and application services.

    You can however inject services registered in the ConfigureServices() method in the Configure() method.

    链接地址: http://www.djcxy.com/p/28402.html

    上一篇: Python模块(它是共享库)如何在没有.py文件的情况下导入?

    下一篇: ASP.NET 5如何注入启动的依赖关系?