-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHostContextExtensions.cs
43 lines (36 loc) · 1.24 KB
/
HostContextExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using Bet.AspNet.DependencyInjection.Legacy;
using Bet.Extensions.LegacyHosting;
namespace Bet.AspNet.LegacyHosting
{
public static class HostContextExtensions
{
/// <summary>
/// Configure Asp.Net Mvc4 Dependency Injection.
/// </summary>
/// <param name="host"></param>
/// <returns></returns>
public static IHost ConfigureMvcDependencyResolver(this IHost host)
{
var resolver = new ServiceScopeResolver(host.Services);
// Set MVC Resolver
DependencyResolver.SetResolver(resolver);
// Set WebApi Resolver
GlobalConfiguration.Configuration.DependencyResolver = resolver;
ServiceScopeModule.SetServiceProvider(host.Services);
return host;
}
/// <summary>
/// Configure Asp.Net WebForms Dependency Injection.
/// </summary>
/// <param name="host"></param>
/// <returns></returns>
public static IHost ConfigureWebFormsResolver(this IHost host)
{
HttpRuntime.WebObjectActivator = new AspNetWebFormsDependencyResolver(host.Services);
return host;
}
}
}