Exemplo n.º 1
0
        /// <summary>
        /// Call once to initialize the context.
        /// </summary>
        /// <typeparam name="TSite">The CMS site model type.</typeparam>
        /// <param name="cacheConfig">The cache config instance.</param>
        /// <param name="umbracoConfig">The umbraco config instance.</param>
        /// <param name="mapBuild">The map build instance.</param>
        /// <param name="cacheBuild">The cache build instance.</param>
        public static void Init <TSite>(ICacheConfig cacheConfig, IUmbracoConfig umbracoConfig, IMapBuild mapBuild, ICacheBuild cacheBuild)
            where TSite : class, ISite
        {
            MapRegistry   = new MapRegistry();
            Mapper        = new Mapper(MapRegistry);
            CacheRegistry = new CacheRegistry(cacheConfig);
            QueryFactory  = new UmbracoQueryFactory();
            CmsFetcher    = new UmbracoFetcher(umbracoConfig);
            Registry      = new Registry(MapRegistry, Mapper, CacheRegistry, QueryFactory, CmsFetcher);
            SiteCaches    = new SiteCaches(CacheRegistry);

            _siteFunc = () =>
            {
                var cache = SiteCaches.Default;
                var host  = HttpContext.Current?.Request.Url.Host ?? string.Empty;
                var sites = cache.Fetch <TSite>()?.ToList();
                return(sites?.FirstOrDefault(site => site.Hosts?.Contains(host) ?? false) ?? sites?.FirstOrDefault());
            };

            _cacheFunc = () =>
            {
                var site = _siteFunc();
                return(SiteCaches.Get(site) as Cache);
            };

            mapBuild.Setup(Registry);
            cacheBuild.Setup(CacheRegistry);
        }
Exemplo n.º 2
0
 public ConfigController(IOptions <ApiConfig> config, IUmbracoConfig umbraco, ICacheConfig cache, ICache cmsCache)
 {
     _config        = config.Value;
     _umbracoConfig = umbraco;
     _cacheConfig   = cache;
     _cache         = cmsCache;
 }
Exemplo n.º 3
0
 public UmbracoFetcher(IUmbracoConfig config)
 {
     _config = config;
 }