introduce ITransientService interface for auto registration of transient services (for DBContexts and Repositories)
This commit is contained in:
		| @ -250,7 +250,7 @@ namespace Microsoft.Extensions.DependencyInjection | ||||
|             var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies(); | ||||
|             foreach (var assembly in assemblies) | ||||
|             { | ||||
|                 // dynamically register module services, contexts, and repository classes | ||||
|                 // dynamically register module scoped services (ie. client service classes) | ||||
|                 var implementationTypes = assembly.GetInterfaces<IService>(); | ||||
|                 foreach (var implementationType in implementationTypes) | ||||
|                 { | ||||
| @ -261,6 +261,17 @@ namespace Microsoft.Extensions.DependencyInjection | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 // dynamically register module transient services (ie. server DBContext, repository classes) | ||||
|                 implementationTypes = assembly.GetInterfaces<ITransientService>(); | ||||
|                 foreach (var implementationType in implementationTypes) | ||||
|                 { | ||||
|                     if (implementationType.AssemblyQualifiedName != null) | ||||
|                     { | ||||
|                         var serviceType = Type.GetType(implementationType.AssemblyQualifiedName.Replace(implementationType.Name, $"I{implementationType.Name}")); | ||||
|                         services.AddScoped(serviceType ?? implementationType, implementationType); | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 // dynamically register hosted services | ||||
|                 var serviceTypes = assembly.GetTypes(hostedServiceType); | ||||
|                 foreach (var serviceType in serviceTypes) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Shaun Walker
					Shaun Walker