public MemberInjectionDescriptor(MemberInfo member, ServiceDependencyAttribute attribute) { _member = member; var serviceType = attribute.ServiceType ?? member switch { PropertyInfo property => property.PropertyType, FieldInfo field => field.FieldType, _ => throw new ArgumentException("Invalid member type."), }; if (attribute.IsRequired) { if (string.IsNullOrEmpty(attribute.Provider)) { _valueFactory = (provider, target) => { if (ServiceModular.TryGetContract(target, serviceType, out var contract)) { return(provider.GetRequiredService(contract)); } else { return(provider.GetRequiredService(serviceType)); } } } ; else { _valueFactory = (provider, target) => { if (ServiceModular.TryGetContract(attribute.Provider, serviceType, out var contract)) { return(provider.GetRequiredService(contract)); } else { return(provider.GetRequiredService(serviceType)); } } }; } else { if (string.IsNullOrEmpty(attribute.Provider)) { _valueFactory = (provider, target) => { if (ServiceModular.TryGetContract(target, serviceType, out var contract)) { return(provider.GetService(contract)); } else { return(provider.GetService(serviceType)); } } } ; else { _valueFactory = (provider, target) => { if (ServiceModular.TryGetContract(attribute.Provider, serviceType, out var contract)) { return(provider.GetService(contract)); } else { return(provider.GetService(serviceType)); } } }; } }
public MemberInjectionDescriptor(MemberInfo member, ServiceDependencyAttribute attribute) { _member = member; var serviceType = attribute.ServiceType ?? member switch { PropertyInfo property => property.PropertyType, FieldInfo field => field.FieldType, _ => throw new ArgumentException("Invalid member type."), }; if (IsServiceAccessor(serviceType, out var accessorType)) { _valueFactory = (provider, target) => ActivatorUtilities.CreateInstance(provider, accessorType, new object[] { GetApplicationModule(member.ReflectedType) }); return; } if (attribute.IsRequired) { if (string.IsNullOrEmpty(attribute.Provider)) { _valueFactory = (provider, target) => { if (ServiceModular.TryGetContract(target, serviceType, out var contract)) { return(provider.GetRequiredService(contract)); } else { return(provider.GetRequiredService(serviceType)); } } } ; else { _valueFactory = (provider, target) => { if (ServiceModular.TryGetContract(attribute.Provider, serviceType, out var contract)) { return(provider.GetRequiredService(contract)); } else { return(provider.GetRequiredService(serviceType)); } } }; } else { if (string.IsNullOrEmpty(attribute.Provider)) { _valueFactory = (provider, target) => { if (ServiceModular.TryGetContract(target, serviceType, out var contract)) { return(provider.GetService(contract)); } else { return(provider.GetService(serviceType)); } } } ; else { _valueFactory = (provider, target) => { if (ServiceModular.TryGetContract(attribute.Provider, serviceType, out var contract)) { return(provider.GetService(contract)); } else { return(provider.GetService(serviceType)); } } }; } }