Skip to content

Commit 43a442e

Browse files
authored
Merge branch 'master' into release/5.11
2 parents 858a40c + 6c3bb69 commit 43a442e

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

README.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,25 @@ Install-Package Unity.Microsoft.DependencyInjection
1616
- In the `WebHostBuilder` add `UseUnityServiceProvider(...)` method
1717

1818
```C#
19-
public static IWebHost BuildWebHost(string[] args) =>
20-
WebHost.CreateDefaultBuilder(args)
21-
.UseUnityServiceProvider() <---- Add this line
22-
.UseStartup<Startup>()
23-
.Build();
19+
public static IHostBuilder CreateHostBuilder(string[] args) =>
20+
Host.CreateDefaultBuilder(args)
21+
.UseUnityServiceProvider() <---- Add this line
22+
.ConfigureWebHostDefaults(webBuilder =>
23+
{
24+
webBuilder.UseStartup<Startup>();
25+
});
2426
```
2527

2628
- In case Unity container configured via application configuration or by convention this container could be used to initialize service provider.
2729

2830
```C#
29-
public static IWebHost BuildWebHost(string[] args) =>
30-
WebHost.CreateDefaultBuilder(args)
31-
.UseUnityServiceProvider(_container) <---- or add this line
32-
.UseStartup<Startup>()
33-
.Build();
31+
public static IHostBuilder CreateHostBuilder(string[] args) =>
32+
Host.CreateDefaultBuilder(args)
33+
.UseUnityServiceProvider(_container) <---- Add this line
34+
.ConfigureWebHostDefaults(webBuilder =>
35+
{
36+
webBuilder.UseStartup<Startup>();
37+
});
3438
```
3539

3640
- Add optional method to your `Startup` class
@@ -42,24 +46,19 @@ public void ConfigureContainer(IUnityContainer container)
4246
}
4347
```
4448

45-
### Resolving Startup
46-
47-
Startup class instance is resolved from Unity if it is configured as default container.
48-
49-
5049
### Resolving Controllers from Unity
5150

5251
By default ASP resolves controllers using built in activator. To enable resolution of controllers from Unity you need to add following line to MVC configuration:
5352
```C#
5453
public void ConfigureServices(IServiceCollection services)
5554
{
56-
services.AddMvc()
57-
.SetCompatibilityVersion(CompatibilityVersion.Version_xxx)
58-
.AddControllersAsServices(); <-- Add this line
55+
...
56+
services.AddControllersAsServices(); <-- Add this line
57+
...
5958
}
6059
```
6160

6261
## Examples
6362

64-
For example of using Unity with Core 2.0 Web application follow [this link](https://github.com/unitycontainer/examples/tree/v5.x/src/web/ASP.Net.Unity.Example)
63+
For example of using Unity with Core 3.1 Web application follow [this link](https://github.com/unitycontainer/examples/tree/master/src/web/ASP.Net.Unity.Example)
6564

0 commit comments

Comments
 (0)