public static void RegisterFromAssembly(IServiceCollection services) { Dictionary <string, Type> namedServices = new Dictionary <string, Type>(); var typesToRegister = typeof(RegisterDataProviderServices).GetTypeInfo().Assembly.DefinedTypes.Where(i => (typeof(IDataProviderService)).IsAssignableFrom(i.AsType())); foreach (var typeToRegister in typesToRegister) { var typeToRegisterAsType = typeToRegister.AsType(); var typeAttributes = typeToRegister.GetCustomAttributes <DataProviderServiceNameAttribute>(false); var registerWithNames = typeAttributes.Select(i => i.Name).ToList(); if (!registerWithNames.Any()) { registerWithNames = new List <string>() { typeToRegisterAsType.Name }; } services.AddTransient(typeToRegisterAsType); foreach (var registerName in registerWithNames) { namedServices.Add(registerName, typeToRegisterAsType); } } var namedServiceResolver = new NamedServiceResolver(services, namedServices); services.AddSingleton <INamedServiceResolver>(namedServiceResolver); }
public HelpController(ISettingService <HygouSetting> Setting, NamedServiceResolver <SF.Common.Documents.IDocumentService> DocServiceResolver) { this.Setting = Setting.Value; this.DocService = DocServiceResolver("pc-help"); }