Example #1
0
        /// <summary>
        /// Add customer repository.
        /// </summary>
        /// <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);
        }
        /// <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.IsRepository(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);
        }