Ejemplo n.º 1
0
        public static IContainer ConfigureContainer(this IAppBuilder app, HttpConfiguration config, IReadOnlyCollection<Assembly> applicationAssemblies, IEnumerable<Module> dependencyModules, WebOption webOption)
        {
            var builder = new ContainerBuilder();

            foreach (var module in dependencyModules)
                builder.RegisterModule(module);

            var assemblies = applicationAssemblies.ToArray();

            ConfigureContainer(builder, webOption, assemblies);

            if (webOption.UseApi)
                builder.RegisterWebApiFilterProvider(config);

            var container = builder.Build();

            if (webOption.UseApi)
                config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            if (webOption.UseMvc)
                DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            app.UseAutofacMiddleware(container);

            if (webOption.UseApi)
                app.UseAutofacWebApi(config);

            return container;
        }
Ejemplo n.º 2
0
        public void Configuration(IAppBuilder app)
        {
            var option = new WebOption
            {
                UseMvc = true,
                UseApi = true
            };

            Configure(app, option);
        }
Ejemplo n.º 3
0
        public static void ConfigureContainer(ContainerBuilder builder, WebOption webOption, params Assembly[] applicationAssemblies)
        {
            var assemblies = applicationAssemblies.ToArray();

            if (webOption.UseMvc)
            {
                builder.RegisterControllers(assemblies);
                builder.RegisterFilterProvider();
                builder.RegisterSource(new ViewRegistrationSource());
            }

            if (webOption.UseApi)
                builder.RegisterApiControllers(assemblies);
        }
Ejemplo n.º 4
0
        protected virtual void Configure(IAppBuilder app, WebOption webOption)
        {
            HttpConfiguration config = null;

            if (webOption.UseMvc)
            {
                ConfigureMvcRoutes(RouteTable.Routes);
                ConfigureMvcFilters(GlobalFilters.Filters);
                ConfigureMvcViewEngines(ViewEngines.Engines);
            }

            if (webOption.UseApi)
            {
                config = new HttpConfiguration();
                ConfigureApiRoutes(config);
                ConfigureApiFilters(config);
                ConfigureApiConventions(config);

                app.UseWebApi(config);
            }

            ConfigureValidation();
            ConfigureContainer(app, config, webOption);
        }
Ejemplo n.º 5
0
        public static IContainer ConfigureContainer(this IAppBuilder app, HttpConfiguration config, IReadOnlyCollection<Module> dependencyModules, WebOption webOption)
        {
            var assemblies = new[] { Assembly.GetCallingAssembly() };

            return app.ConfigureContainer(config, assemblies, dependencyModules, webOption);
        }
Ejemplo n.º 6
0
        protected override void ConfigureContainer(IAppBuilder app, HttpConfiguration config, WebOption webOption)
        {
            var modules = GetModules();

            app.ConfigureContainer(config, modules, webOption);
        }
Ejemplo n.º 7
0
 protected virtual void ConfigureContainer(IAppBuilder app, HttpConfiguration config, WebOption webOption)
 {
 }