简体   繁体   English

ASP.Net核心使用什么依赖注入框架?

[英]What Dependency Injection Framework Does ASP.Net Core Use?

I've started dabbling in ASP.Net Core , and found out that Dependency Injection is a First-class Citizen in the ASP.Net Core framework and that it is built-in and ready to use for injecting various services and libraries. 我已经开始涉足ASP.Net Core ,并发现依赖注入是ASP.Net Core框架中的一流公民,它内置并可以用于注入各种服务和库。

I would like to know which Dependency Injection framework they are using. 我想知道他们正在使用哪个依赖注入框架 Their docs at Introduction to Dependency Injection in ASP.NET Core 他们的文档介绍了ASP.NET核心中的依赖注入

ASP.NET Core is designed from the ground up to support and leverage dependency injection. ASP.NET Core是从头开始设计的,用于支持和利用依赖注入。 ASP.NET Core applications can leverage built-in framework services by having them injected into methods in the Startup class, and application services can be configured for injection as well ASP.NET Core应用程序可以通过将它们注入Startup类中的方法来利用内置框架服务,并且还可以配置应用程序服务以进行注入

Did they write their own from ground-up? 他们是否从头开始写自己的? Or are they re-using an existing open source Dependency Injection framework. 或者他们是否重用现有的开源依赖注入框架。 If yes, which one? 如果是的话,哪一个?

The reason for asking, besides natural curiosity, is also that I want to use the same framework they are using in ASP.Net Core , in my .Net 4.6.1. 除了天生的好奇心之外,问的原因还在于我想在我的.Net 4.6.1.中使用他们在ASP.Net Core中使用的相同框架.Net 4.6.1. ASP.Net Web API application. ASP.Net Web API应用程序。

Because I've found most DI frameworks to be very slow and bloated, even Unity . 因为我发现大多数DI框架都非常缓慢和臃肿,甚至是Unity

In contrast, the ASP.Net CORE DI framework seems to be really fast and lean. 相比之下,ASP.Net CORE DI框架似乎非常快速和精益。

.NET Core is open source, so we can examine this for ourselves. .NET Core是开源的,所以我们可以自己检查一下。 The base repo is at: 基础仓库位于:

https://github.com/dotnet/corefx https://github.com/dotnet/corefx

And the ASP.NET Core Repo is at: ASP.NET Core Repo位于:

https://github.com/aspnet/home https://github.com/aspnet/home

Going to the "DependencyInjection" Repo ( https://github.com/aspnet/DependencyInjection ) and navigating down in the source we find https://github.com/aspnet/DependencyInjection/blob/dev/src/Microsoft.Extensions.DependencyInjection/ServiceProvider.cs 转到“DependencyInjection”Repo( https://github.com/aspnet/DependencyInjection )并在源代码中向下导航,我们找到https://github.com/aspnet/DependencyInjection/blob/dev/src/Microsoft.Extensions。 DependencyInjection / ServiceProvider.cs

Reading through that file it sure looks like a DI container. 通过该文件读取它确实看起来像一个DI容器。 Its fair to say that Microsoft wrote their own, though they also support using existing ones according to the documentation in the Dependency Injection repo. 可以说微软自己编写了自己的版本,尽管他们也支持根据依赖注入回购中的文档使用现有版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM