Beispiel #1
0
        public void AopTest()
        {
            IocContainer.Initialize(false);
            var test = IocContainer.Create <ITestService>();

            test.Test(new Test.dto {
                Name = "张三夺夺夺夺", Age = 180
            });
        }
Beispiel #2
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     DependencyResolver.SetResolver(new AutofacDependencyResolver(IocContainer.Create()));
     AutoMapperConfig.RegisterMappings();
 }
        public static IServiceProvider ConfigureServices(this IServiceCollection services, IConfiguration configuration, IHostingEnvironment environment)
        {
            //add application configuration
            var config = services.ConfigureStartupConfig <WebConfiguration>(configuration.GetSection("Application"));

            services.AddSingleton(config);

            //add hosting configuration
            var hostingConfig = services.ConfigureStartupConfig <HostingConfiguration>(configuration.GetSection("Hosting"));

            hostingConfig.ApplicationRootPath = environment.ContentRootPath;
            hostingConfig.ContentRootPath     = environment.WebRootPath;
            hostingConfig.ModulesRootPath     = Path.Combine(environment.ContentRootPath, "Modules");
            services.AddSingleton(hostingConfig);

            //most of API providers require TLS 1.2 nowadays
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            //add non-latin character support
            services.AddTextEncoder();

            //add response compression
            services.AddGzipResponseCompression();

            //add mvc engine
            var builder = services.AddMvc();

            services.AddHangfire(hf => hf.UseMemoryStorage());

            //add custom view engine
            services.AddViewEngine();

            if (environment.ApplicationName.Equals("microCommerce.Web",
                                                   StringComparison.InvariantCultureIgnoreCase))
            {
                //add theme support
                services.AddThemeSupport();
            }

            //add accessor to HttpContext
            services.AddHttpContextAccessor();

            //add anti forgery
            services.AddCustomAntiForgery();

            //add custom session
            services.AddCustomHttpSession(config);

            //create, initialize and register dependencies
            var engine          = IocContainer.Create();
            var serviceProvider = engine.RegisterDependencies(services, configuration, config);

            //add module features support
            builder.AddModuleFeatures(services);

            return(serviceProvider);
        }
Beispiel #4
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            config.DependencyResolver = new AutofacWebApiDependencyResolver(IocContainer.Create());

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }
Beispiel #5
0
        public static IServiceProvider ConfigureApiServices(this IServiceCollection services, IConfigurationRoot configuration, IHostingEnvironment environment)
        {
            //add application configuration parameters
            var config = services.ConfigureStartupConfig <ServiceConfiguration>(configuration.GetSection("Service"));

            services.AddSingleton(config);

            //add hosting configuration parameters
            var hostingConfig = services.ConfigureStartupConfig <HostingConfiguration>(configuration.GetSection("Hosting"));

            hostingConfig.ApplicationRootPath = environment.ContentRootPath;
            hostingConfig.ContentRootPath     = environment.WebRootPath;
            hostingConfig.ModulesRootPath     = Path.Combine(environment.ContentRootPath, "Modules");
            services.AddSingleton(hostingConfig);

            //most of API providers require TLS 1.2 nowadays
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            //add response compression
            services.AddGzipResponseCompression();

            //add mvc engine
            var builder = services.AddWebApi();

            //add accessor to HttpContext
            services.AddHttpContextAccessor();

            //add swagger
            services.AddCustomizedSwagger(config);

            //create, initialize and register dependencies
            var engine          = IocContainer.Create();
            var serviceProvider = engine.RegisterDependencies(services, configuration, config);

            //add module features support
            builder.AddModuleFeatures(services);

            return(serviceProvider);
        }
 public T Create <T>() where T : class
 {
     return(innerContainer.Create <T>());
 }
Beispiel #7
0
 /// <summary>
 /// Creates the container
 /// </summary>
 /// <returns>initialized container</returns>
 protected static IWindsorContainer CreateTestContainer()
 {
     return(IocContainer.Create("UnitTest", false)
            .AddLog4net("log4net.unittest.config"));
 }