public TKeyType GetService <TKeyType>( String keyName, Action <TKeyType, ServiceProvider, IServiceConfiguration> setup, Int32 setupOrder = 0, Type[] generics = default) where TKeyType : class => this.GetService(ServiceConfigurationKey.From <TKeyType>(keyName), setup as Action <Object, ServiceProvider, IServiceConfiguration>, setupOrder, generics) as TKeyType;
/// <summary> /// Registers a new ServiceConfiguration. /// </summary> /// <typeparam name="TKeyType">The primary lookup key type for the current service configuration.</typeparam> /// <param name="keyName">The primary lookup key name for the current service configuration.</param> /// <param name="lifetime">The default lifetime for the described service.</param> /// <param name="typeFactory">The <see cref="ITypeFactory.Type"/> to be used when building a new instance of this service.</param> /// <param name="baseCacheKey">The minimum cache key. All ancestors between <paramref name="baseCacheKey"/> and <paramref name="key"/> will be used as <see cref="ServiceConfigurationContext.CacheKeys"/>.</param> /// <param name="priority">The priority value for this specific descriptor. All services will be sorted by priority when their the service provider is created.</param> public void RegisterServiceConfiguration <TKeyType>( String keyName, ServiceLifetime lifetime, Type typeFactory, ServiceConfigurationKey baseCacheKey, Int32 priority = 0) => this.Add(new ServiceConfigurationContext(ServiceConfigurationKey.From <TKeyType>(keyName), lifetime, typeFactory, baseCacheKey, priority));
object IServiceProvider.GetService(Type serviceType) => this.GetService(ServiceConfigurationKey.From(serviceType));
public TKey GetService <TKey>( Action <TKey, ServiceProvider, IServiceConfiguration> setup, Int32 setupOrder = 0, Type[] generics = default) where TKey : class => this.GetService(ServiceConfigurationKey.From <TKey>(), setup as Action <Object, ServiceProvider, IServiceConfiguration>, setupOrder, generics) as TKey;
public TKey GetService <TKey>( Type[] generics = default) where TKey : class => this.GetService(ServiceConfigurationKey.From <TKey>(), generics) as TKey;
public TKeyType GetService <TKeyType>( String keyName, Type[] generics = default) where TKeyType : class => this.GetService(ServiceConfigurationKey.From <TKeyType>(keyName), generics) as TKeyType;
internal ServiceProvider(ServiceCollection services) { // Construct all relevant ITypeFactory instances. _typeFactories = services.TypeFactories .GroupBy(tf => tf.Type) .Select(g => g.OrderByDescending(tf => tf.Priority).First()) .Select(tf => tf.CreateTypeFactory(services.BuilderActions)) .ToDictionary(tf => tf.Type, tf => tf); // Construct all IServiceConfiguration instances. _registeredServices = services.ServiceConfigurations .OrderByDescending(sc => sc.Priority) .Select(sc => sc.CreateServiceConfiguration(_typeFactories, services.SetupActions)) .GroupBy(sc => sc.Key) .ToDictionary(g => g.Key, g => g.ToArray()); // Construct all ComponentConfiguration instances. _componentConfigurations = services.ComponentConfigurations .Select(c => c.CreateComponentConfiguration(_registeredServices, services.ComponentFilters)) .GroupBy(c => c.EntityServiceConfigurationKey) .ToDictionary(g => g.Key, g => g.ToArray()); // Add placeholders for every registered service type with no configurations foreach (ServiceConfigurationKey key in _registeredServices.Keys.Where(k => k.Inherits(ServiceConfigurationKey.From <IEntity>()))) { if (!_componentConfigurations.ContainsKey(key)) { _componentConfigurations[key] = new ComponentConfiguration[0]; } } _primaryActiveService = new Dictionary <ServiceConfigurationKey, IServiceManager>(); _activeServices = new Dictionary <ServiceConfigurationServiceConfigurationKey, IServiceManager>(); this.IsRoot = true; this.Root = this; }
public void RegisterSetup <TKey>( Action <TKey, ServiceProvider, IServiceConfiguration> method, Int32 order = 0) where TKey : class => this.Add(new SetupAction(ServiceConfigurationKey.From <TKey>(), (i, p, c) => method(i as TKey, p, c), order));
public void RegisterSetup <TKeyType>( String keyName, Action <TKeyType, ServiceProvider, IServiceConfiguration> method, Int32 order = 0) where TKeyType : class => this.Add(new SetupAction(ServiceConfigurationKey.From <TKeyType>(keyName), (i, p, c) => method(i as TKeyType, p, c), order));
/// <summary> /// Register a new component to an entity. /// </summary> /// <typeparam name="TComponentKeyType">The component's key type</typeparam> /// <typeparam name="TEntityKeyType">The entity's key type</typeparam> /// <param name="componentKeyName">The component's key name</param> /// <param name="entityKeyName">The entity's key name</param> public void RegisterComponent <TComponentKeyType, TEntityKeyType>( String componentKeyName, String entityKeyName) where TComponentKeyType : class, IComponent where TEntityKeyType : class, IEntity => this.RegisterComponent(ServiceConfigurationKey.From <TComponentKeyType>(componentKeyName), ServiceConfigurationKey.From <TEntityKeyType>(entityKeyName));
/// <summary> /// Register a new component to an entity. /// </summary> /// <typeparam name="TComponentKey">The component's key</typeparam> /// <typeparam name="TEntityKey">The entity's key</typeparam> public void RegisterComponent <TComponentKey, TEntityKey>() where TComponentKey : class, IComponent where TEntityKey : class, IEntity => this.RegisterComponent(ServiceConfigurationKey.From <TComponentKey>(), ServiceConfigurationKey.From <TEntityKey>());
/// <summary> /// Registers a new ServiceConfiguration. /// </summary> /// <typeparam name="TKey">The primary lookup key type for the current service configuration.</typeparam> /// <param name="lifetime">The default lifetime for the described service.</param> /// <param name="typeFactory">The <see cref="ITypeFactory.Type"/> to be used when building a new instance of this service.</param> /// <param name="priority">The priority value for this specific descriptor. All services will be sorted by priority when their the service provider is created.</param> public void RegisterServiceConfiguration <TKey>( ServiceLifetime lifetime, Type typeFactory = default, Int32 priority = 0) => this.Add(new ServiceConfigurationContext(ServiceConfigurationKey.From <TKey>(), lifetime, typeFactory, priority));
/// <summary> /// Registers a new ServiceConfiguration. /// </summary> /// <typeparam name="TKey">The primary lookup key type for the current service configuration.</typeparam> /// <param name="lifetime">The default lifetime for the described service.</param> /// <param name="typeFactory">The <see cref="ITypeFactory.Type"/> to be used when building a new instance of this service.</param> /// <param name="cacheKeys">When a non <see cref="ServiceLifetime.Transient"/> service gets created the value will be linked within the defined cache keys so that any of the values will return the currently defined service.</param> /// <param name="priority">The priority value for this specific descriptor. All services will be sorted by priority when their the service provider is created.</param> public void RegisterServiceConfiguration <TKey>( ServiceLifetime lifetime, Type typeFactory, IEnumerable <ServiceConfigurationKey> cacheKeys, Int32 priority = 0) => this.Add(new ServiceConfigurationContext(ServiceConfigurationKey.From <TKey>(), lifetime, typeFactory, cacheKeys, priority));