public static ServiceCollection AddTextile(this ServiceCollection services, Action <ThreadClientOptions> configure) { if (services == null) { throw new ArgumentNullException(nameof(services)); } services.AddOptions(); services.AddThreadContext(); services.TryAddSingleton <IThreadClientFactory, ThreadClientFactory>(); services.TryAddScoped <IThreadClient, ThreadClient>(); services.TryAddSingleton <IPostConfigureOptions <ThreadContextOptions>, ThreadContextPostConfigureOptions>(); services.AddAutoMapper(typeof(ThreadProfile)); services.AddGrpcClient <API.APIClient>((serviceProvider, options) => { IThreadContext context = serviceProvider.GetRequiredService <IThreadContext>(); options.Address = new Uri(context.Host); }); services.Configure(configure); return(services); }