nam*_*nam 3 asp.net asp.net-core-mvc .net-core asp.net-core
使用VS2015创建ASP.NET Core RC2项目时,您将获得内置的项目Services folder.有人可以提供服务文件夹使用示例的说明.或者一些可能有帮助的链接.
也许,您已经阅读了有关此候选版本的文档.https://docs.asp.net/en/latest/fundamentals/dependency-injection.html
ASP.NET Core是从头开始设计的,用于支持和利用依赖注入.ASP.NET Core应用程序可以通过将它们注入Startup类中的方法来利用内置框架服务,并且还可以配置应用程序服务以进行注入.ASP.NET Core提供的默认服务容器提供了一个最小的功能集,并不打算替换其他容器.
服务,在这种情况下,是指一类实例,它提供了一些操作或数据到应用程序的其他部分.不要误解它,服务不是指Web服务,但它可能是.
Asp.net核心有一个集成的IoC容器,您可以在启动类中设置依赖关系.
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1153 次 |
| 最近记录: |