ASP.NET Core 的 `Core` 有几种写法?
一、概述本文将会根据情况持续更新。 二、WebHost.CreateDefaultHostBuilder
public static IWebHostBuilder CreateDefaultBuilder(); public static IWebHostBuilder CreateDefaultBuilder(string[] args); public static IWebHostBuilder CreateDefaultBuilder<TStartup>(string[] args) where TStartup : class;
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder<Startup>(args);
三、IWebHostBuilder.UseStartup
public static IWebHostBuilder UseStartup(this IWebHostBuilder hostBuilder,Type startupType); public static IWebHostBuilder UseStartup<TStartup>(this IWebHostBuilder hostBuilder) where TStartup : class;
如果不使用 public static IWebHostBuilder Configure(this IWebHostBuilder hostBuilder,Action<IApplicationBuilder> configureApp);
四、使用第三方依赖注入在 // ConfigureContainer is where you can register things directly // with Autofac. This runs after ConfigureServices so the things // here will override registrations made in ConfigureServices. // Don't build the container; that gets done for you. If you // need a reference to the container,you need to use the // "Without ConfigureContainer" mechanism shown later. public void ConfigureContainer(ContainerBuilder builder) { builder.RegisterModule(new AutofacModule()); } 第二种是实现 // ConfigureServices is where you register dependencies. This gets // called by the runtime before the Configure method,below. public IServiceProvider ConfigureServices(IServiceCollection services) { // Add services to the collection. services.AddMvc(); // Create the container builder. var builder = new ContainerBuilder(); // Register dependencies,populate the services from // the collection,and build the container. // // Note that Populate is basically a foreach to add things // into Autofac that are in the collection. If you register // things in Autofac BEFORE Populate then the stuff in the // ServiceCollection can override those things; if you register // AFTER Populate those registrations can override things // in the ServiceCollection. Mix and match as needed. builder.Populate(services); builder.RegisterType<MyType>().As<IMyType>(); this.ApplicationContainer = builder.Build(); // Create the IServiceProvider based on the container. return new AutofacServiceProvider(this.ApplicationContainer); } 第三种方法是采用自定义 public static class AbpAutofacAbpApplicationCreationOptionsExtensions { public static void UseAutofac(this AbpApplicationCreationOptions options) { ContainerBuilder builder = new ContainerBuilder(); options.Services.AddObjectAccessor<ContainerBuilder>(builder); options.Services.AddSingleton<IServiceProviderFactory<ContainerBuilder>>((IServiceProviderFactory<ContainerBuilder>) new AbpAutofacServiceProviderFactory(builder)); } }
五、服务注册点包含名为
六、中间件注册点包含名为
参考资料ASP.NET Core 中的应用启动 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – 我应该关注受感染的zip文件吗?
- asp.net-mvc – EF,ASP MVC依赖注入.多个并发请求和数据库连
- ASP.NET显示SVN版本号
- ASP.NET Ajax库死了吗?
- asp.net-mvc-4 – 使用knockout.js我需要从服务器调用更新我
- asp.net-mvc – 如何在Razor MVC 4中使用Ajax Control Tool
- asp.net – 避免表格重新提交
- asp.net-mvc – 使用Ajax.Beginform的RedirectToAction,意外
- asp.net – 配置IIS服务器使用Aurelia框架并推送状态
- 找出ASP.NET WebForms中控件的生命周期的哪个阶段
- entity-framework – ASP.NET动态数据:如何在下
- asp.net-mvc – MVC – 一次创建对象和相关对象
- asp.net – 获取用户及其角色的列表
- asp.net-core – 模型集合上的ModelBinding
- asp.net-mvc-3 – 如何在mvc3 razor视图中使用会
- asp.net – web.config使自定义成员资格提供程序
- asp.net-mvc-2 – 具有异常参数的ModelState.Add
- asp.net-mvc – ASP.Net MVC:发送JSON到控制器
- 从头编写 asp.net core 2.0 web api 基础框架
- asp.net-mvc – 搜索页面MVC路由(隐藏动作,没有斜