// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var db = new DbInstaller(); db.InstallServices(services, Configuration); var mvc = new MvcInstaller(); mvc.InstallServices(services, Configuration); services.AddAutoMapper(typeof(Startup)); var swagger = new SwaggerInstaller(); swagger.InstallServices(services, Configuration); var cache = new CacheInstaller(); cache.InstallServices(services, Configuration); }
/// <summary>Registers the type mappings with the Unity container.</summary> /// <param name="container">The unity container to configure.</param> /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks> public static void RegisterTypes(IUnityContainer container) { // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements. // container.LoadConfiguration(); // TODO: Register your types here // container.RegisterType<IProductRepository, ProductRepository>(); //string connectionString = WebConfigurationManager.ConnectionStrings["cs"].ConnectionString; string hibernateCfgFileName = System.Web.Hosting.HostingEnvironment.MapPath("~/bin/hibernate.cfg.xml"); XElement root = XElement.Load(hibernateCfgFileName); var nsMgr = new XmlNamespaceManager(new NameTable()); nsMgr.AddNamespace("NC", "urn:nhibernate-configuration-2.2"); string connectionString = root.XPathSelectElement("//NC:property[@name='connection.connection_string']", nsMgr).Value; //регистрация NHibernate-репозиториев NHibernateDataInstaller.Install(container, new PerRequestLifetimeManager()); NHibernateRepositoryInstaller.Install(container); //регистрация кэша string redisConnectionString = WebConfigurationManager.AppSettings["cache:RedisConnectionString"]; CacheLocation defaultLocation = CacheLocation.InMemory; Enum.TryParse(WebConfigurationManager.AppSettings["cache:DefaultLocation"], out defaultLocation); CacheInstaller.Install(redisConnectionString, defaultLocation, container, new PerRequestLifetimeManager()); //регистрация Мигратора MigratorInstaller.Install(container, connectionString); DataServiceCommonInstaller.Install(container); //регистрация дата-сервисов DataServiceInstaller.Install(container); //регистрация шины EventBusInstaller.Install(container, WebConfigurationManager.AppSettings["RabbitMQHost"], WebConfigurationManager.AppSettings["ServiceAddress"], WebConfigurationManager.AppSettings["RabbitMQUserName"], WebConfigurationManager.AppSettings["RabbitMQPassword"]); container.RegisterType <JsResourceHelper>(); }
private IMethodReturn run(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext, CacheAttribute cacheAttribute) { var result = getNext()(input, getNext); if (result.Exception == null) { if (cacheAttribute != null) { var cacheImplementation = CacheInstaller.GetCache(cacheAttribute.Location); if (cacheImplementation != null) { IList <object> methodPapameters = new List <object>(); IEnumerator enumerator = input.Arguments.GetEnumerator(); int ind = 0; while (enumerator.MoveNext()) { if (cacheAttribute.SkippedParameterIndexes == null || !cacheAttribute.SkippedParameterIndexes.Contains(ind)) { IForCacheKeyValue forCacheKeyValue = enumerator.Current as IForCacheKeyValue; if (forCacheKeyValue != null) { methodPapameters.Add(forCacheKeyValue.GetForCacheKeyValue()); } else { methodPapameters.Add(enumerator.Current); } } ind++; } if (cacheAttribute.Invalidate) { if (!String.IsNullOrWhiteSpace(cacheAttribute.InvalidateCacheKeyTemplates)) { string[] invalidateCacheKeyTemplates = cacheAttribute.InvalidateCacheKeyTemplates.Split(','); foreach (var t in invalidateCacheKeyTemplates) { cacheImplementation.Remove(String.Format(t.Trim(), methodPapameters.ToArray())); } } } else { string cacheKey = String.Format(cacheAttribute.CacheKeyTemplate, methodPapameters.ToArray()); result.ReturnValue = cacheImplementation .AddOrGetExisting(cacheKey, () => { return(result.ReturnValue); }, cacheAttribute.ExpirationSeconds); } return(result); } return(result); } else { return(result); } } else { return(input.CreateExceptionMethodReturn(result.Exception)); } }