Browse Source
Update Autofac-Integration.md
UseAufoFac in ASP.NET Core Application
pull/11222/head
DongZirun
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
11 additions and
14 deletions
-
docs/zh-Hans/Autofac-Integration.md
|
|
|
@ -32,26 +32,23 @@ namespace MyCompany.MyProject |
|
|
|
|
|
|
|
### ASP.NET Core 应用程序 |
|
|
|
|
|
|
|
如下所示, 在 **Startup.cs** 文件中调用 `UseAutofac()`: |
|
|
|
如下所示, 在 **Program.cs** 文件中调用 `UseAutofac()`: |
|
|
|
|
|
|
|
````csharp |
|
|
|
public class Startup |
|
|
|
public class Program |
|
|
|
{ |
|
|
|
public IServiceProvider ConfigureServices(IServiceCollection services) |
|
|
|
public static int Main(string[] args) |
|
|
|
{ |
|
|
|
services.AddApplication<MyWebModule>(options => |
|
|
|
{ |
|
|
|
//Integrate Autofac! |
|
|
|
options.UseAutofac(); |
|
|
|
}); |
|
|
|
|
|
|
|
return services.BuildServiceProviderFromFactory(); |
|
|
|
CreateHostBuilder(args).Build().Run(); |
|
|
|
} |
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app) |
|
|
|
{ |
|
|
|
app.InitializeApplication(); |
|
|
|
} |
|
|
|
internal static IHostBuilder CreateHostBuilder(string[] args) => |
|
|
|
Host.CreateDefaultBuilder(args) |
|
|
|
.ConfigureWebHostDefaults(webBuilder => |
|
|
|
{ |
|
|
|
webBuilder.UseStartup<Startup>(); |
|
|
|
}) |
|
|
|
.UseAutofac(); //Integrate Autofac! |
|
|
|
} |
|
|
|
```` |
|
|
|
|
|
|
|
|