Conversation
|
I am not sure if this produces the same result (I didn't spend time much :). I will consider this later since it has not an important enhancement. |
|
|
| .FirstOrDefault(i => i.GetTypeInfo().IsGenericType && | ||
| i.GetGenericTypeDefinition() == typeof(IServiceProviderFactory<>)); | ||
|
|
||
| if (factoryInterface == null) |
There was a problem hiding this comment.
You can't use var when reassigning to an existing variable
if (factoryInterface == null)
factoryInterface = service.ServiceType;
if (factoryInterface == null ||
!factoryInterface.IsGenericType ||
factoryInterface.GetGenericTypeDefinition() != typeof(IServiceProviderFactory<>))
{
// handle error or return
}
maniya81
left a comment
There was a problem hiding this comment.
var factoryInterface = service.ImplementationInstance?.GetType()
.GetInterfaces()
.FirstOrDefault(i => i.IsGenericType &&
i.GetGenericTypeDefinition() == typeof(IServiceProviderFactory<>));
Removed var - Should be a simple assignment since factoryInterface is already declared
Removed GetTypeInfo() - Direct access to GetGenericTypeDefinition() in latest .NET
Now that the following code:
requires 'IServiceProviderFactory' Service Type,
For intuition and efficiency, my code may be better. And strickly saying, they are not of equal value. If registered service type 'XxxServiceProviderFactory', the former code may
throw AbpException($"Could not find {typeof(IServiceProviderFactory<TContainerBuilder>).FullName} in {services}."), my code won't.It will just return 'services.BuildServiceProvider()'.