public static IServiceCollection RegisterEmployeeService(this IServiceCollection services, IConfiguration configuration) { services.Configure <ServiceSettings>(Settings.ServiceSettingConstants.EmployeeService, configuration.GetSection("Services:NetTcp:EmployeeService")); services.Configure <ServiceSettings>(configuration.GetSection("Services:NetTcp:Default")); services.AddSingleton <IEmployeeClientProxyFactory>(provider => { var logger = provider.GetRequiredService <ILogger>(); var options = provider.GetRequiredService <Microsoft.Extensions.Options.IOptionsSnapshot <ServiceSettings> >(); var proxySettings = new ClientProxySettings(ServiceSettingConstants.EmployeeService, options); return(new EmployeeClientProxyFactory(proxySettings, logger)); }); services.AddTransient <EmployeeClientDemo>(); services.AddTransient <FactoryEmployeeClientDemo>(); services.AddTransient <AutomaticConfigurationEmployeeClientDemo>(); services.AddTransient <WcfGeneratedServiceDemo>(); services.AddTransient <Func <string, IEmployeeClientDemo> >(provider => key => { if (key == DemoConstants.EmployeeClientDemo) { return(provider.GetService <EmployeeClientDemo>()); } else if (key == DemoConstants.FactoryEmployeeClientDemo) { return(provider.GetService <FactoryEmployeeClientDemo>()); } else if (key == DemoConstants.AutomaticConfigurationEmployeeClientDemo) { return(provider.GetService <AutomaticConfigurationEmployeeClientDemo>()); } else if (key == DemoConstants.WcfGeneratedServiceDemo) { return(provider.GetService <WcfGeneratedServiceDemo>()); } throw new KeyNotFoundException(); }); return(services); }
public static IServiceCollection RegisterEmployeeService(this IServiceCollection services, IConfiguration configuration) { services.Configure <ServiceSettings>(Settings.ServiceSettingConstants.EmployeeService, configuration.GetSection("Services:NetTcp:EmployeeService")); services.Configure <ServiceSettings>(configuration.GetSection("Services:NetTcp:Default")); services.AddSingleton <IEmployeeClientProxyFactory>(provider => { var options = provider.GetRequiredService <Microsoft.Extensions.Options.IOptionsSnapshot <ServiceSettings> >(); var proxySettings = new ClientProxySettings(ServiceSettingConstants.EmployeeService, options); return(new EmployeeClientProxyFactory(proxySettings)); }); services.AddTransient <EmployeeClientDemo>(); services.AddTransient <Func <string, IEmployeeClientDemo> >(provider => key => { return(provider.GetService <EmployeeClientDemo>()); }); return(services); }