问题描述
我正在将网站从asp.net 4.5迁移到5.0.以前,我使用 System.Web.Mvc
来获取 DependencyResolver.SetResolve
来注册依赖项.是否有任何出版物或文档可以将我指向新的 Microsoft.AspNet.Mvc
版本?
I'm migrating my site, from asp.net 4.5 to 5.0. Previously, I used System.Web.Mvc
to get DependencyResolver.SetResolve
to register dependencies. Is there any publication or documentation that can point me to the new Microsoft.AspNet.Mvc
version?
推荐答案
http://docs.asp.net/en/latest/fundamentals/dependency-injection.html
这是asp.net 5依赖项注入的官方文档.
That's official documentation for dependency injection for asp.net 5.
依赖注入现在已内置到asp.net 5中,但是您可以自由使用其他库,例如autofac.默认设置对我来说很好.
Dependency injection is now built into asp.net 5 but you are free to use other libraries like autofac. The default one is working fine for me.
在您的starup类中,您有一个像这样的方法
In your starup class, you have a method like this
public void ConfigureServices(IServiceCollection services)
{
//IServiceCollection acts like a container and you
//can register your classes like this:
services.AddTransient<IEmailSender, AuthMessageSender>();
services.Singleton<ISmsSender, AuthMessageSender>();
services.AddScoped<ICharacterRepository, CharacterRepository>();
}
这些是一些服务终身和注册选项
这篇关于DependencyResolver Asp.net 5.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!