/// <summary>
        /// Automatically scan and register all repositories within an assembly.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="assembly">The assembly in which the custom repository resides</param>
        /// <param name="selector">a selector,see <see cref="CustomerRepositorySelector"/>.</param>
        public static void AutoRegisterRepositories(this ModuleConfigServiceContext context, Assembly assembly, CustomerRepositorySelector selector)
        {
            var allRepoTypes = assembly.GetTypes().Where(s => TypeHelper.IsConcrete(s) && typeof(IRepository).IsAssignableFrom(s));

            List <(Type repoInterface, Type repo)> result = new();

            foreach (var repo in allRepoTypes)
            {
                var interfaces = repo.GetInterfaces().Where(s => !s.Name.Contains(nameof(IRepository))).Reverse();

                int tempIndex = 0;
                foreach (var repoInterface in interfaces)
                {
                    if (selector(repo, repoInterface, tempIndex))
                    {
                        result.Add((repoInterface, repo));
                    }

                    tempIndex++;
                }
            }

            result.ForEach(s =>
            {
                context.RegisterRepository(s.repoInterface, s.repo);
            });
        }
 /// <summary>
 /// Automatically scan and register all repositories within an assembly.use default selector.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="assembly">The assembly in which the custom repository resides</param>
 public static void AutoRegisterRepositories(this ModuleConfigServiceContext context, Assembly assembly)
 {
     AutoRegisterRepositories(context, assembly, (repo, repoInterface, index) =>
     {
         return(repoInterface.Name.Contains(repo.Name));
     });
 }
Ejemplo n.º 3
0
        public void ConfigServices(ModuleConfigServiceContext context)
        {
            var services = context.Services ??
                           throw new ArgumentNullException(nameof(context.Services));

            _logger.LogInformation("MiCake:ActivateServices......");

            StartModuleLifetime(_modules, bootInfos.Where(s => s.Type == ModuleBootType.ConfigService), context);
            _configServiceActions?.Invoke(context);

            _logger.LogInformation("MiCake:ActivateServices Completed.");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add customer repository.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="serviceType">Interface type of repository</param>
        /// <param name="implementationType">Implementation type of repository</param>
        public static void RegisterRepository(this ModuleConfigServiceContext context, Type serviceType, Type implementationType)
        {
            if (!DomainTypeHelper.IsRepository(serviceType))
            {
                throw new ArgumentException($"{serviceType.FullName} is not a {nameof(IRepository)},Please give a right type!");
            }

            if (!DomainTypeHelper.IsRepository(implementationType))
            {
                throw new ArgumentException($"{implementationType.FullName} is not a {nameof(IRepository)},Please give a right type!");
            }

            var services = context.Services;

            services.AddTransient(serviceType, implementationType);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Add customer <see cref="IDomainService"/>
        /// </summary>
        /// <param name="context"></param>
        /// <param name="serviceType">Interface type of domain service</param>
        /// <param name="implementationType">ImplementationType type of domain service</param>
        /// <param name="miCakeServiceLifeTime"><see cref="MiCakeServiceLifetime"/></param>
        public static void RegisterDomainService(
            this ModuleConfigServiceContext context,
            Type serviceType,
            Type implementationType,
            MiCakeServiceLifetime miCakeServiceLifeTime = MiCakeServiceLifetime.Transient)
        {
            if (!DomainTypeHelper.IsDomainService(serviceType))
            {
                throw new ArgumentException($"{serviceType.FullName} is not a domain service,Please give a right type!");
            }

            if (!DomainTypeHelper.IsDomainService(implementationType))
            {
                throw new ArgumentException($"{implementationType.FullName} is not a domain service,Please give a right type!");
            }

            var serviceDescpritor = new ServiceDescriptor(serviceType, implementationType, miCakeServiceLifeTime.ConvertToMSLifetime());

            context.Services.TryAdd(serviceDescpritor);
        }
Ejemplo n.º 6
0
        public void ConfigServices(ModuleConfigServiceContext context)
        {
            var services = context.Services;

            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            _logger.LogInformation("MiCake:ActivateServices...");

            for (int index = 0; index < configServicesLifetimes.Count; index++)
            {
                var des = configServiceDes[index];
                foreach (var miCakeModule in _modules)
                {
                    _moduleLogger.LogModuleInfo(miCakeModule, $"MiCake {des}: ");
                    configServicesLifetimes[index](miCakeModule.Instance, context);
                }
            }
            _configServiceActions?.Invoke(context);

            _logger.LogInformation("MiCake:ActivateServices Completed.....");
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Add customer repository.
 /// </summary>
 /// <typeparam name="TService">Interface type of repository</typeparam>
 /// <typeparam name="TImpl">Implementation type of repository</typeparam>
 public static void RegisterRepository <TService, TImpl>(this ModuleConfigServiceContext context)
 {
     RegisterRepository(context, typeof(TService), typeof(TImpl));
 }
Ejemplo n.º 8
0
 public virtual void PreConfigServices(ModuleConfigServiceContext context)
 {
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Add customer <see cref="IDomainService"/>
 /// </summary>
 /// <typeparam name="TService">Type of domain service</typeparam>
 /// <param name="context"></param>
 /// <param name="miCakeServiceLifeTime"><see cref="MiCakeServiceLifetime"/></param>
 public static void RegisterDomainService <TService>(
     this ModuleConfigServiceContext context,
     MiCakeServiceLifetime miCakeServiceLifeTime = MiCakeServiceLifetime.Transient)
 {
     RegisterDomainService(context, typeof(TService), typeof(TService), miCakeServiceLifeTime);
 }