/// <summary> /// Convert <see cref="MiCakeServiceLifetime"/> to microsoft di <see cref="ServiceLifetime"/> /// </summary> /// <param name="miCakeServiceLifetime"></param> /// <returns></returns> public static ServiceLifetime ConvertToMSLifetime(this MiCakeServiceLifetime miCakeServiceLifetime) { return(miCakeServiceLifetime switch { MiCakeServiceLifetime.Singleton => ServiceLifetime.Singleton, MiCakeServiceLifetime.Transient => ServiceLifetime.Transient, MiCakeServiceLifetime.Scoped => ServiceLifetime.Scoped, _ => ServiceLifetime.Transient });
/// <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); }
/// <summary> /// Add customer <see cref="IDomainService"/> /// </summary> /// <typeparam name="TService">Interface type of domain service</typeparam> /// <typeparam name="TImpl">ImplementationType type of domain service</typeparam> /// <param name="context"></param> /// <param name="miCakeServiceLifeTime"><see cref="MiCakeServiceLifetime"/></param> public static void RegisterDomainService <TService, TImpl>( this ModuleConfigServiceContext context, MiCakeServiceLifetime miCakeServiceLifeTime = MiCakeServiceLifetime.Transient) { RegisterDomainService(context, typeof(TService), typeof(TImpl), miCakeServiceLifeTime); }