Esempio n. 1
0
        /// <summary>
        /// Add modulos to current solution.
        /// For ASP.NET Core 3.1+ it's recommended to use <see cref="ModulosServiceProviderFactory" />.
        /// </summary>
        /// <param name="services">IServiceCollection instance.</param>
        /// <param name="modulos">Instance of modulos application</param>
        /// <param name="additionalData">Additional data available for modules.</param>
        public static IServiceCollection AddModulos(this IServiceCollection services,
                                                    ModulosApp modulos,
                                                    params object[] additionalData)
        {
            var factory = new ModulosServiceProviderFactory(modulos, null, additionalData);

            factory.CreateBuilder(services);
            return(services);
        }
Esempio n. 2
0
        /// <summary>
        /// Add modulos to current solution.
        /// For ASP.NET Core 3.1+ it's recommended to use <see cref="ModulosServiceProviderFactory" />.
        /// </summary>
        /// <param name="services">IServiceCollection instance.</param>
        /// <param name="modulos">Instance of modulos application</param>
        /// <param name="modifier">
        /// Enables to redefine detected modules. For example, it may be used to
        /// load only particular modules in test environments.
        /// </param>
        /// <param name="additionalData">Additional data available for modules.</param>
        public static IServiceCollection AddModulos(this IServiceCollection services,
                                                    ModulosApp modulos,
                                                    Action <AutoRegistrationModule> modifier = null,
                                                    params object[] additionalData)
        {
            var factory = new ModulosServiceProviderFactory(modulos, modifier, additionalData);

            factory.CreateBuilder(services);
            return(services);
        }
        protected ModulosServiceProviderFactoryBase(ModulosApp modulos,
                                                    Func <IServiceCollection, TBuilder> builderFactory,
                                                    Action <AutoRegistrationModule> modifier = null,
                                                    params object[] parameters)
        {
            _modulos        = modulos;
            _builderFactory = builderFactory;
            _modifier       = modifier;
            _parameters     = parameters?.ToDictionary
                              (
                e => e.GetType(),
                e => e
                              ) ?? new Dictionary <Type, object>();

            if (!_parameters.ContainsKey(typeof(IAppInfo)))
            {
                _parameters.Add(typeof(IAppInfo), modulos.AppInfo);
            }

            if (!_parameters.ContainsKey(typeof(Assembly[])))
            {
                _parameters.Add(typeof(Assembly[]), modulos.Assemblies);
            }

            if (!_parameters.ContainsKey(typeof(IAssemblyExplorer)))
            {
                var assemblyExplorer = new AssemblyExplorer
                                       (
                    (Assembly[])_parameters[typeof(Assembly[])]
                                       );

                _parameters.Add(typeof(IAssemblyExplorer), assemblyExplorer);
            }

            if (!_parameters.ContainsKey(typeof(ITypeExplorer)))
            {
                var assemblyExplorer = (IAssemblyExplorer)_parameters[typeof(IAssemblyExplorer)];
                _parameters.Add(typeof(ITypeExplorer), new TypeExplorer(assemblyExplorer));
            }
        }
 /// <summary>
 /// Register modulos dependencies and executes defined DI modules.
 /// </summary>
 /// <param name="modulos">Instance of modulos app.</param>
 /// <param name="modifier">
 /// Allows changing modulus auto registration modules (e.q. prevents load).
 /// </param>
 /// <param name="parameters">
 /// Additional parameters available for auto registration modules.
 /// </param>
 public ModulosServiceProviderFactory(ModulosApp modulos,
                                      Action <AutoRegistrationModule> modifier = null, params object[] parameters)
     : base(modulos, collection => collection, modifier, parameters)
 {
 }