Beispiel #1
0
        /// <summary>
        /// Registers canned modules
        /// </summary>
        /// <param name="registry"></param>
        /// <param name="modules"></param>
        protected static void RegisterScannedModules(ILocatorRegistry registry, IEnumerable <Type> modules)
        {
            foreach (var module in modules)
            {
                if (StartupModuleType.IsAssignableFromCheck(module))
                {
                    registry.Add(StartupModuleType, module, null, Lifecycle.Singleton);
                }

                if (LocatorConfigureType.IsAssignableFromCheck(module))
                {
                    registry.Add(LocatorConfigureType, module, null, Lifecycle.Singleton);
                }
            }
        }
Beispiel #2
0
 void ILocatorConfigure.Configure(ILocatorRegistry registry, ILocatorConfigureEngine engine)
 {
     if (RegisterScopedHttpContext)
     {
         registry.Add(typeof(System.Web.HttpContextBase), _ => new System.Web.HttpContextWrapper(System.Web.HttpContext.Current), Lifecycle.Scoped);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Registers IStartupModules
 /// </summary>
 /// <param name="registry"></param>
 protected void RegisterStartupModuleCollection(ILocatorRegistry registry)
 {
     if (StartupModuleCollection?.Count > 0)
     {
         foreach (var module in StartupModuleCollection)
         {
             if (module.ModuleInstance is object)
             {
                 registry.Add(StartupModuleType, module.ModuleInstance);
             }
             else if (module.ModuleType is object)
             {
                 registry.Add(StartupModuleType, module.ModuleType, null, Lifecycle.Singleton);
             }
         }
     }
 }
Beispiel #4
0
 /// <summary>
 /// Registers ILocatorConfigure modules
 /// </summary>
 /// <param name="registry"></param>
 protected void RegisterLocatorConfigureCollection(ILocatorRegistry registry)
 {
     if (LocatorConfigureModuleCollection?.Count > 0)
     {
         foreach (var module in LocatorConfigureModuleCollection)
         {
             registry.Add(LocatorConfigureType, module);
         }
     }
 }
        private bool AddRegistration(Registration registration, ILocatorRegistry registry)
        {
            registry.Add
            (
                registration.ServiceType,        // service
                registration.ImplementationType, // implementation
                lifecycle: registration.Lifecycle
            );

            return(true);
        }
        public void Configure(ILocatorRegistry container, ILocatorConfigureEngine engine)
        {
            try
            {
                container.Add(typeof(IRemove), typeof(BaseImpl), null, Lifecycle.Singleton);
            }
            catch
            {
                RegisterException = true;
            }

            if (container is ILocatorRegistryWithRemove removable)
            {
                removable.Remove(typeof(IRemove));
                SupportsServiceRemoval = true;
            }

            container.Add <BaseTest, BaseImpl>(lifecycle: Lifecycle.Singleton);
            container.Add(typeof(IFooTwo), locator => FooTwoFactory.CreateFoo(), Lifecycle.Transient);
        }
Beispiel #7
0
        public void Configure(ILocatorRegistry locator, IStartupEngine engine)
        {
            _Locator = locator;

#if NETCOREAPP1_1
            var mOptions = new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions()
            {
                CompactOnMemoryPressure = true, ExpirationScanFrequency = new System.TimeSpan(0, 0, 10)
            };
            locator.Add(typeof(Microsoft.Extensions.Options.IOptions <Microsoft.Extensions.Caching.Memory.MemoryCacheOptions>), new Microsoft.Extensions.Options.OptionsWrapper <Microsoft.Extensions.Caching.Memory.MemoryCacheOptions>(mOptions));
#endif
        }
Beispiel #8
0
        void ILocatorConfigure.Configure(ILocatorRegistry registry, ILocatorConfigureEngine engine)
        {
            engine.OnLocatorStartupComplete += () =>
            {
                IEnumerable <Type> renderingTypes = engine.Configuration
                                                    .AssemblyScanner.GetTypesFor(typeof(RenderingDocumentAliasAttribute));

                foreach (var rendering in renderingTypes.Where(x => !x.IsAbstract() && !x.IsInterface()))
                {
                    registry?.Add(rendering, rendering, lifecycle: Lifecycle.Transient);
                }
            };
        }
Beispiel #9
0
        internal static void AddServicesToLocator(IServiceCollection services, ILocatorRegistry locator)
        {
            for (int i = 0; i < services.Count; i++)
            {
                var service  = services[i];
                var lifetime = ConvertLifeTime(service.Lifetime);

                if (service.ImplementationType is object)
                {
                    locator.Add(service.ServiceType, service.ImplementationType, lifecycle: lifetime);
                }
                else if (service.ImplementationFactory is object)
                {
                    locator.Add(service.ServiceType,
                                l => service.ImplementationFactory(l.GetServiceProvider()),
                                lifetime);
                }
                else
                {
                    locator.Add(service.ServiceType, service.ImplementationInstance);
                }
            }
        }
        void ILocatorConfigure.Configure(ILocatorRegistry registry, ILocatorConfigureEngine engine)
        {
            engine.OnLocatorStartupComplete += () =>
            {
                IApiControllerRegistrationSetup controllerRegistrationSetup = GetApiControllerRegistrationSetup?.Invoke() ??
                                                                              new ApiControllerRegistrationSetup();

                if (controllerRegistrationSetup.EnableApiControllerRegistrations == true)
                {
                    IEnumerable <Type> controllerTypes = engine.Configuration.AssemblyScanner.GetTypesFor(typeof(ApiController));

                    foreach (var controller in controllerTypes.Where(x => x.IsAbstract == false))
                    {
                        registry?.Add(controller, controller, lifecycle: Lifecycle.Transient);
                    }
                }
            };
        }
Beispiel #11
0
 /// <summary>
 /// Adds a transient lifecycle service
 /// </summary>
 /// <param name="registry"></param>
 /// <param name="serviceType"></param>
 /// <param name="implementationType"></param>
 /// <returns></returns>
 public static ILocatorRegistry AddTransient(this ILocatorRegistry registry, Type serviceType, Type implementationType)
 {
     registry.Add(serviceType, implementationType, lifecycle: Lifecycle.Transient);
     return(registry);
 }
 public void Configure(ILocatorRegistry registry, ILocatorConfigureEngine engine)
 {
     registry.Add <TestFoo, TestFoo>();
 }
Beispiel #13
0
 /// <summary>
 /// Adds an instance
 /// </summary>
 /// <typeparam name="TService"></typeparam>
 /// <param name="registry"></param>
 /// <param name="instance"></param>
 /// <returns></returns>
 public static ILocatorRegistry AddInstance <TService>(this ILocatorRegistry registry, TService instance)
 {
     registry.Add(typeof(TService), instance);
     return(registry);
 }
Beispiel #14
0
 /// <summary>
 /// Adds a transient lifecycle service
 /// </summary>
 /// <typeparam name="TService"></typeparam>
 /// <typeparam name="TImplementation"></typeparam>
 /// <param name="registry"></param>
 /// <returns></returns>
 public static ILocatorRegistry AddTransient <TService, TImplementation>(this ILocatorRegistry registry) where TImplementation : TService
 {
     registry.Add <TService, TImplementation>(lifecycle: Lifecycle.Transient);
     return(registry);
 }
 void ILocatorConfigure.Configure(ILocatorRegistry registry, ILocatorConfigureEngine engine)
 {
     // use scoped to not create many per web request, also cannot use given locator to resolve scoped items
     registry.Add(typeof(UmbracoContext), locator => EnsureUmbracoContext(), Lifecycle.Scoped);
     registry.Add(typeof(UmbracoHelper), locator => new UmbracoHelper(EnsureUmbracoContext()), Lifecycle.Scoped);
 }
Beispiel #16
0
 /// <summary>
 /// Adds a singleton lifecycle service
 /// </summary>
 /// <typeparam name="TService"></typeparam>
 /// <typeparam name="TImplementation"></typeparam>
 /// <param name="registry"></param>
 /// <returns></returns>
 public static ILocatorRegistry AddSingleton <TService, TImplementation>(this ILocatorRegistry registry) where TImplementation : TService
 {
     registry.Add <TService, TImplementation>(lifecycle: Lifecycle.Singleton);
     return(registry);
 }
Beispiel #17
0
 /// <summary>
 /// Adds a singleton lifecycle service
 /// </summary>
 /// <param name="registry"></param>
 /// <param name="serviceType"></param>
 /// <param name="implementationType"></param>
 /// <returns></returns>
 public static ILocatorRegistry AddSingleton(this ILocatorRegistry registry, Type serviceType, Type implementationType)
 {
     registry.Add(serviceType, implementationType, lifecycle: Lifecycle.Singleton);
     return(registry);
 }