Esempio n. 1
0
        public static IContainer Initialize()
        {
            var configuration = new ConfigurationService();

            var builder = new ContainerBuilder();

            builder.Register(c => configuration).As <ConfigurationService>().SingleInstance();
            builder.Register(c => configuration.CurrentConfiguration).As <IAppConfiguration>().SingleInstance();
            builder.Register(c => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();

            return(AutofacBootstrapper.Initialize(new ContainerBuilder()));
        }
Esempio n. 2
0
        public void Configuration(IAppBuilder app)
        {
            var configurationService = new ConfigurationService();
            var config = new HttpConfiguration();

#if DEBUG
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Debug()
                         .CreateLogger();

            config.Services.Add(typeof(IExceptionLogger), new DebugExceptionLogger());
#else
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Elmah()
                         .CreateLogger();
#endif
            // Autofac
            var builder = new ContainerBuilder();
            builder.Register(c => app.GetDataProtectionProvider()).InstancePerRequest();
            builder.Register(c => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
            builder.Register(c => Log.Logger).As <ILogger>().SingleInstance();
            builder.RegisterType <ElmahSqlLogger>().AsSelf().InstancePerRequest();

            var container = AutofacBootstrapper.Initialize(builder, config, configurationService);

            // Web API
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });
            config.Services.Add(typeof(IExceptionLogger), new ElmahExceptionLogger());
            config.Filters.Add(new ElmahHandleErrorApiAttribute());
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new DefaultContractResolver {
                IgnoreSerializableAttribute = true
            };

            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority      = configurationService.CurrentConfiguration.SiteRoot,
                RequiredScopes = new[] { "api2" },
                ValidationMode = ValidationMode.ValidationEndpoint
            });

            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(config);

            config.Formatters.Add(new BsonMediaTypeFormatter());

            app.UseWebApi(config);

            ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
        }
Esempio n. 3
0
        public static Task EnsureBootstrapped()
        {
            if (!_isInitialized)
            {
                lock (_lockObject)
                {
                    if (!_isInitialized)
                    {
                        AutofacBootstrapper.Initialize();
                        _isInitialized = true;
                    }
                }
            }

            return(Task.CompletedTask);
        }
Esempio n. 4
0
        protected override Task BeforeAsync()
        {
            if (!_isInitialized)
            {
                Environment.SetEnvironmentVariable("KEKIRI_OUTPUT", "console,files");
                lock (_lockObject)
                {
                    if (!_isInitialized)
                    {
                        AutofacBootstrapper.Initialize();
                        _isInitialized = true;
                    }
                }
            }

            return(Task.CompletedTask);
        }
Esempio n. 5
0
        public static IContainer GetBuiltWebProjectContainer()
        {
            var containerBuilder = new ContainerBuilder();

            return(AutofacBootstrapper.Initialize(containerBuilder));
        }
Esempio n. 6
0
 public void Setup()
 {
     AutofacBootstrapper.Initialize();
 }
Esempio n. 7
0
 protected override IMvxIoCProvider CreateIocProvider()
 {
     return(new AutofacMvxIocProvider(AutofacBootstrapper.Initialize()));
 }
Esempio n. 8
0
 public void RunBeforeAnyTests()
 {
     AutofacBootstrapper.Initialize(
         c => c.Modules.Add(new FakesModule())
         );
 }