Ejemplo n.º 1
0
        /// <summary>
        /// Add the services of the modules.
        /// </summary>
        /// <param name="serviceCollection">Service collection</param>
        public static void AddModuleServices(this IServiceCollection serviceCollection)
        {
            Type             serviceType      = typeof(IDependencyRegister);
            IList <Assembly> moduleAssemblies = AssembliesContext.Instance.GetList();

            if (moduleAssemblies is null)
            {
                return;
            }

            for (int i = 0; i < moduleAssemblies.Count; i++)
            {
                Type[] types = moduleAssemblies[i].GetTypes();

                for (int j = 0; j < types.Length; j++)
                {
                    Type type = types[j];

                    if (serviceType.IsAssignableFrom(type) && !type.GetTypeInfo().IsAbstract)
                    {
                        IDependencyRegister dependancyRegister = Activator.CreateInstance(type) as IDependencyRegister;
                        dependancyRegister.SetDependencyInjections(serviceCollection);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the dependency injection.
        /// </summary>
        /// <param name="services">Services.</param>
        /// <param name="configuration">Configuration.</param>
        /// <param name="assemblies">Assemblies.</param>
        public static void AddDependencyInjection(
            this IServiceCollection services,
            IConfiguration configuration,
            params Assembly[] assemblies)
        {
            Type serviceType = typeof(IDependencyRegister);

            for (int i = 0; i < assemblies.Length; i++)
            {
                Type[] types = assemblies[i].GetTypes();

                for (int j = 0; j < types.Length; j++)
                {
                    Type type = types[j];

                    if (serviceType.IsAssignableFrom(type) && !type.GetTypeInfo().IsAbstract)
                    {
                        IDependencyRegister dependancyRegister = Activator.CreateInstance(type) as IDependencyRegister;
                        dependancyRegister.SetDependencyInjections(services, configuration);
                    }
                }
            }
        }