/// <summary> /// 负责调用autofac框架实现业务逻辑层和数据仓储层程序集中的类型对象的创建 /// 负责创建MVC控制器类的对象(调用控制器中的有参构造函数),接管DefaultControllerFactory的工作 /// </summary> public static void Register() { var cacheConfig = ConfigurationBuilder.BuildConfiguration(settings => settings.WithMaxRetries(1000).WithMemcachedCacheHandle("cacheManager/memcached")); var builder = new ContainerBuilder(); //缓存注册 builder.RegisterGeneric(typeof(BaseCacheManager <>)) .WithParameters(new[] { new TypedParameter(typeof(ICacheManagerConfiguration), cacheConfig) }) .As(typeof(ICacheManager <>)) .SingleInstance(); //builder.RegisterAssemblyTypes(this.ThisAssembly) //.Where(t => t.IsAssignableTo<IService>()) //.AsImplementedInterfaces() //.InstancePerLifetimeScope(); ExceptionlessClient.Default.Configuration.UseInMemoryStorage(); ExceptionlessClient.Default.Configuration.UseReferenceIds(); ExceptionlessClient.Default.Configuration.SetDefaultMinLogLevel(MinLogLevel()); // 日志 builder.RegisterType <ExceptionLessLogger>().As <ILogger>().SingleInstance(); builder.RegisterType <AuthService>().As <IAuthService>().SingleInstance(); // 获取包含继承了IService接口类的程序集 builder.RegisterModule <KStar.Form.Mvc.WebServiceModule>(); builder.RegisterModule <KStar.Domain.WebServiceModule>(); builder.RegisterModule <KStar.Form.Domain.WebServiceModule>(); builder.RegisterModule <KStar.Platform.WebServiceModule>(); // Register your MVC controllers. (MvcApplication is the name of // the class in Global.asax.) builder.RegisterControllers(Assembly.GetExecutingAssembly()) .PropertiesAutowired() // Enable property injection .InstancePerLifetimeScope(); // OPTIONAL: Register model binders that require DI. builder.RegisterModelBinders(typeof(MvcApplication).Assembly); builder.RegisterModelBinderProvider(); // OPTIONAL: Register web abstractions like HttpContextBase. builder.RegisterModule <AutofacWebTypesModule>(); // OPTIONAL: Enable property injection in view pages. //builder.RegisterSource(new ViewRegistrationSource()); // OPTIONAL: Enable property injection into action filters. builder.RegisterFilterProvider(); // Set the dependency resolver to be Autofac. var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
private void AddCache(IServiceCollection services) { var cacheManagerConfig = ConfigurationBuilder.BuildConfiguration(cfg => { cfg.WithGzJsonSerializer() .WithMicrosoftMemoryCacheHandle("runTimeMemory"); }); services.AddSingleton(cacheManagerConfig); services.AddCacheManager(); }
private void AddCache(IServiceCollection services) { var cacheManagerConfig = ConfigurationBuilder.BuildConfiguration(cfg => { cfg.WithGzJsonSerializer() .WithMicrosoftMemoryCacheHandle("runTimeMemory"); }); services.AddSingleton(cacheManagerConfig); services.AddCacheManager(); services.AddDataProtection() .PersistKeysToFileSystem(new DirectoryInfo("DataProtection-Keys")); }
private void AddCache(IServiceCollection services) { var cacheManagerConfig = ConfigurationBuilder.BuildConfiguration(cfg => { cfg.WithJsonSerializer() .WithRedisConfiguration("redis", Configuration.GetConnectionString("Redis")) .WithRedisBackplane("redis") .WithRedisCacheHandle("redis", true); }); services.AddSingleton(cacheManagerConfig); services.AddCacheManager(); var redisConnection = ConnectionMultiplexer.Connect(Configuration.GetConnectionString("Redis")); services.AddSingleton <IConnectionMultiplexer>(redisConnection); services.AddDataProtection() .PersistKeysToRedis(redisConnection, "DataProtection-Keys"); }