1
1
using System ;
2
- using System . Linq ;
3
- using System . Reflection ;
4
- using System . Web . Compilation ;
5
- using System . Web . Http ;
6
- using System . Web . Mvc ;
7
2
using App . Api ;
8
- using App . Core . Contracts ;
9
- using App . Core . Implementations ;
10
- using App . Infrastructure . Di ;
11
3
using App . Infrastructure . Logging . Owin ;
12
4
using Autofac ;
13
- using Autofac . Integration . Mvc ;
14
- using Autofac . Integration . WebApi ;
15
5
using Microsoft . Owin ;
16
6
using Microsoft . Owin . Security ;
17
7
using Microsoft . Owin . Security . Infrastructure ;
@@ -44,11 +34,10 @@ public void Configuration(IAppBuilder app)
44
34
app . UseAutofacMiddleware ( container ) ;
45
35
ConfigureOAuth ( app , container ) ;
46
36
ConfigureOAuthTokenConsumption ( app , container ) ;
47
-
48
37
app . UseCommonLogging ( ) ;
49
38
}
50
39
51
- private void ConfigureOAuth ( IAppBuilder app , IComponentContext componentContext )
40
+ private static void ConfigureOAuth ( IAppBuilder app , IComponentContext componentContext )
52
41
{
53
42
//var issuer = ConfigurationManager.AppSettings["tokenIssuer"];
54
43
@@ -78,57 +67,13 @@ private void ConfigureOAuth(IAppBuilder app, IComponentContext componentContext)
78
67
// });
79
68
}
80
69
81
- private void ConfigureOAuthTokenConsumption ( IAppBuilder app , IComponentContext componentContext )
70
+ private static void ConfigureOAuthTokenConsumption ( IAppBuilder app , IComponentContext componentContext )
82
71
{
83
72
app . UseOAuthBearerAuthentication (
84
73
new OAuthBearerAuthenticationOptions
85
74
{
86
75
AccessTokenFormat = componentContext . Resolve < ISecureDataFormat < AuthenticationTicket > > ( )
87
76
} ) ;
88
77
}
89
-
90
- private class AutofacConfig
91
- {
92
- private class Inner { }
93
-
94
- private static IContainer Container { get ; set ; }
95
-
96
- public static IContainer ConfigureContainer ( )
97
- {
98
- var builder = new ContainerBuilder ( ) ;
99
- RegisterAllModules ( builder ) ;
100
-
101
- builder . RegisterApiControllers ( typeof ( AutofacConfig ) . Assembly ) ;
102
- AutowireProperties ( builder ) ;
103
- builder . RegisterControllers ( Assembly . GetExecutingAssembly ( ) ) ;
104
-
105
- RegisterDependencies ( builder ) ;
106
- Container = builder . Build ( ) ;
107
-
108
- DependencyResolver . SetResolver ( new AutofacResolver ( Container ) ) ;
109
- GlobalConfiguration . Configuration . DependencyResolver = new AutofacWebApiDependencyResolver ( Container ) ;
110
-
111
- return Container ;
112
- }
113
-
114
- private static void AutowireProperties ( ContainerBuilder builder )
115
- {
116
- builder . RegisterApiControllers ( typeof ( Inner ) . Assembly ) . PropertiesAutowired ( ) ;
117
-
118
- builder . RegisterType < Global > ( ) . PropertiesAutowired ( ) ;
119
- }
120
-
121
- private static void RegisterAllModules ( ContainerBuilder builder )
122
- {
123
- var assemblies = BuildManager . GetReferencedAssemblies ( ) . Cast < Assembly > ( ) . ToArray ( ) ;
124
- // register modules from assemblies
125
- builder . RegisterAssemblyModules ( assemblies ) ;
126
- }
127
-
128
- private static void RegisterDependencies ( ContainerBuilder builder )
129
- {
130
- builder . Register < IResolver > ( x => new Resolver ( Container ) ) ;
131
- }
132
- }
133
78
}
134
79
}
0 commit comments