// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(c => c.AddPolicy(MyAllowSpecificOrigins, b => { b.AllowAnyHeader().AllowAnyMethod().WithOrigins("http://localhost:4200", "https://www.dmyblog.co"); }) ); ServiceCollectionServiceExtensions.AddScoped <SharesSevice>(services); services.AddSingleton <IEmailConfiguration>(Configuration.GetSection("EmailConfiguration").Get <EmailConfiguration>()); services.AddTransient <IEmailService, EmailService>(); services.Configure <BrotliCompressionProviderOptions>(options => { options.Level = CompressionLevel.Optimal; }); services.AddResponseCompression(options => { IEnumerable <string> MimeTypes = new[] { "text/plain", "text/css", "font/woff2", "application/javascript", "image/x-icon", "image/png", "image/jpeg" }; options.EnableForHttps = true; options.MimeTypes = MimeTypes; options.Providers.Add <GzipCompressionProvider>(); options.Providers.Add <BrotliCompressionProvider>(); }); services.AddControllersWithViews(); }
public void AddCoreServices(IServiceCollection services) { ServiceCollectionDescriptorExtensions.TryAddScoped<IShellStateUpdater, ShellStateUpdater>(services); ServiceCollectionDescriptorExtensions.TryAddScoped<IShellStateManager, NullShellStateManager>(services); dummyVar0 = ServiceCollectionServiceExtensions.AddScoped<IShellDescriptorManagerEventHandler, ShellStateCoordinator>(services); return; }
public static IWebHostBuilder UseHttpListener(this IWebHostBuilder hostBuilder) { return(hostBuilder.ConfigureServices(services => { ServiceCollectionServiceExtensions.AddSingleton <IServer, HttpListenerServer>(services); })); }
public IServiceProvider CreateContainer(ShellSettings settings, ShellBlueprint blueprint) { V_0 = this._serviceProvider.CreateChildContainer(this._applicationServices); dummyVar0 = ServiceCollectionServiceExtensions.AddSingleton<ShellSettings>(V_0, settings); stackVariable8 = V_0; stackVariable9 = ShellContainerFactory.u003cu003ec.u003cu003e9__7_0; if (stackVariable9 == null) { dummyVar1 = stackVariable9; stackVariable9 = new Func<IServiceProvider, IShellConfiguration>(ShellContainerFactory.u003cu003ec.u003cu003e9.u003cCreateContaineru003eb__7_0); ShellContainerFactory.u003cu003ec.u003cu003e9__7_0 = stackVariable9; } dummyVar2 = ServiceCollectionServiceExtensions.AddSingleton<IShellConfiguration>(stackVariable8, stackVariable9); dummyVar3 = ServiceCollectionServiceExtensions.AddSingleton<ShellDescriptor>(V_0, blueprint.get_Descriptor()); dummyVar4 = ServiceCollectionServiceExtensions.AddSingleton<ShellBlueprint>(V_0, blueprint); this.AddCoreServices(V_0); V_1 = this._serviceProvider.CreateChildContainer(this._applicationServices); stackVariable26 = blueprint.get_Dependencies(); stackVariable27 = ShellContainerFactory.u003cu003ec.u003cu003e9__7_3; if (stackVariable27 == null) { dummyVar5 = stackVariable27; stackVariable27 = new Func<KeyValuePair<Type, FeatureEntry>, bool>(ShellContainerFactory.u003cu003ec.u003cu003e9.u003cCreateContaineru003eb__7_3); ShellContainerFactory.u003cu003ec.u003cu003e9__7_3 = stackVariable27; } V_6 = stackVariable26.Where<KeyValuePair<Type, FeatureEntry>>(stackVariable27).GetEnumerator(); try { while (V_6.MoveNext()) { V_7 = V_6.get_Current(); ServiceCollectionDescriptorExtensions.TryAddEnumerable(V_1, ServiceDescriptor.Singleton(Type.GetTypeFromHandle(//
public static IBaseServiceBuilder UseStartup <T>(this IBaseServiceBuilder builder) where T : class, IStartup { return(builder.ConfigureServices(services => { ServiceCollectionServiceExtensions.AddSingleton(services, typeof(IStartup), typeof(T)); })); }
public void RegisterUseCase <TRequest, TUseCase, TImplement>() where TUseCase : class, IUseCase <TRequest, IResponse> where TRequest : IRequest <IResponse> where TImplement : class, TUseCase { ServiceCollectionServiceExtensions.AddSingleton <TUseCase, TImplement>(services); bus.Register <TRequest, TUseCase>(); }
public static IServiceCollection AddPiranhaSimpleCache(this IServiceCollection services, bool clone = false) { if (clone) { return ServiceCollectionServiceExtensions.AddSingleton<ICache, SimpleCacheWithClone>(services); } return ServiceCollectionServiceExtensions.AddSingleton<ICache, SimpleCache>(services); }
/// <summary> /// Add http logger to ILogger /// </summary> /// <param name="endpoint">The http endpoint</param> /// <param name="appendCategoryToEndpoint">Whether append the category name to the http endpoint. If it's appended, it will be used by fluentd http input as the tag</param> public static ILoggingBuilder AddHttp(this ILoggingBuilder builder, string endpoint = "http://localhost:8887", bool appendCategoryToEndpoint = false) { ServiceCollectionServiceExtensions.AddSingleton <ILoggerProvider, HttpLoggerProvider>(builder.Services, provider => { return(new HttpLoggerProvider(endpoint, appendCategoryToEndpoint)); }); return(builder); }
public static IServiceCollection AddExtensionManagerHost(this IServiceCollection services) { dummyVar0 = ServiceCollectionServiceExtensions.AddSingleton <IExtensionManager, ExtensionManager>(services); dummyVar1 = ServiceCollectionServiceExtensions.AddSingleton <ITypeFeatureProvider, TypeFeatureProvider>(services); dummyVar2 = ServiceCollectionServiceExtensions.AddSingleton <IFeaturesProvider, FeaturesProvider>(services); dummyVar3 = ServiceCollectionServiceExtensions.AddSingleton <IExtensionDependencyStrategy, ExtensionDependencyStrategy>(services); dummyVar4 = ServiceCollectionServiceExtensions.AddSingleton <IExtensionPriorityStrategy, ExtensionPriorityStrategy>(services); return(services); }
protected override void ConfigureWebHost(IWebHostBuilder builder) { //ConfigureTestServices which will run after Startup.ConfigureServices. builder.ConfigureAppConfiguration(b => b.AddJsonFile("appSettings.json", optional: true)) .ConfigureTestServices(s => { ServiceCollectionServiceExtensions.AddSingleton <ICouchbaseStartup>(s, p => new Mock <ICouchbaseStartup>().Object); ServiceCollectionServiceExtensions.AddSingleton <ICouchbaseOperations>(s, p => CouchbaseOperations.Object); }); }
void IServiceAttribute.AddService( IServiceCollection services, Type serviceType, Func <IServiceProvider, object> implementationFactory) { ServiceCollectionServiceExtensions.AddSingleton( services, serviceType, implementationFactory); }
public DecoratorBuilder <TInterface> Default <TService>() where TService : class, TInterface { ServiceCollectionServiceExtensions.AddTransient <TService>(_services); var provider = ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(_services); _decoratedService = (TInterface)provider.GetService(typeof(TService)); return(this); }
void IServiceAttribute.AddService( IServiceCollection services, Type serviceType, Type implementationType) { ServiceCollectionServiceExtensions.AddSingleton( services, serviceType, implementationType); }
public static void RegisterAllRequestResponses(IServiceCollection services, Func <Type, RegisterAllRequestResponsesOptions> onConfigure = null) { RegisterAllRequestResponsesOptions registerConfig = null; //we should change this part of configuration because multiple invoke of onConfigure if (onConfigure != null) { registerConfig = onConfigure(null); } else { registerConfig = new RegisterAllRequestResponsesOptions { timeout = TimeSpan.FromSeconds(10), rabbitmqHost = "localhost:5672", namespaces = new string[] { "" } }; } List <TypeInfo> consumersTypes = GetSpecificConsumers(typeof(IRequestResponse), registerConfig.namespaces); foreach (TypeInfo consType in consumersTypes) { Type responseType = null, requestType = null; foreach (var genericType in consType.GetInterfaces()) { if (genericType.IsGenericType && genericType.GetGenericTypeDefinition() == typeof(IRequestResponse <>)) { responseType = genericType.GetGenericArguments()[0]; //response type } else if (genericType.IsGenericType && genericType.GetGenericTypeDefinition() == typeof(IConsumer <>)) { requestType = genericType.GetGenericArguments()[0]; //request type } } Uri serviceAddress = new Uri($"rabbitmq://{registerConfig.rabbitmqHost}/{consType.Name}"); var requestClientGenericType = typeof(IRequestClient <,>).MakeGenericType(new Type[] { requestType, responseType }); ServiceCollectionServiceExtensions.AddScoped(services, requestClientGenericType, new Func <IServiceProvider, object>(sp => { if (onConfigure != null) { registerConfig = onConfigure(consType); } return(Activator.CreateInstance(typeof(MessageRequestClient <,>).MakeGenericType(requestType, responseType), args: new object[] { sp.GetRequiredService <IBus>(), serviceAddress, registerConfig.timeout, registerConfig.timeout, null })); })); } }
public static IServiceCollection AddSetFeaturesDescriptor(this IServiceCollection services) { stackVariable0 = services; stackVariable1 = OrchardCore.Environment.Shell.ServiceCollectionExtensions.u003cu003ec.u003cu003e9__2_0; if (stackVariable1 == null) { dummyVar0 = stackVariable1; stackVariable1 = new Func <IServiceProvider, IShellDescriptorManager>(OrchardCore.Environment.Shell.ServiceCollectionExtensions.u003cu003ec.u003cu003e9.u003cAddSetFeaturesDescriptoru003eb__2_0); OrchardCore.Environment.Shell.ServiceCollectionExtensions.u003cu003ec.u003cu003e9__2_0 = stackVariable1; } dummyVar1 = ServiceCollectionServiceExtensions.AddSingleton <IShellDescriptorManager>(stackVariable0, stackVariable1); return(services); }
/// <summary> /// Add configuration load feature to <paramref name="builder"/>. /// /// If <paramref name="loadInitialConfiguration"/> is true, then load initial configuration <paramref name="configurationLoader"/> upon call. /// </summary> /// <param name="builder"></param> /// <param name="configuration">configuration to monitor</param> /// <param name="switchableLogger">(optional) switch instance to load new configuration to.</param> /// <param name="configurationLoader">(optional) delegate that reads configuration. If not provided then uses <see cref="SerilogConfigurationLoaderExtensions.DefaultConfigurationLoader"/></param> /// <param name="loadInitialConfiguration">(optional) policy whether <paramref name="configurationLoader"/> is ran at this method call</param> /// <returns></returns> public static ILoggingBuilder AddSerilogConfigurationLoader(this ILoggingBuilder builder, IConfiguration configuration, SwitchableLogger switchableLogger = default, Func <IConfiguration, ILogger> configurationLoader = default, bool loadInitialConfiguration = true) { // Assert argument if (builder == null) { throw new ArgumentNullException(nameof(builder)); } // Instance switch instance if (switchableLogger == null) { switchableLogger = new SwitchableLogger(); } // Create configure loader if (configurationLoader == null) { configurationLoader = DefaultConfigurationLoader; } // Load initial configuration if (loadInitialConfiguration) { switchableLogger.Logger = configurationLoader(configuration); } // Service collection IServiceCollection services = builder.Services; // Add switch instance as service ServiceCollectionServiceExtensions.AddSingleton(services, typeof(SwitchableLogger), switchableLogger); // Function container Action <object>[] handleReloadContainer = new Action <object> [1]; // ChangeToken callback handleReloadContainer[0] = o => { try { // Create new configuration ILogger newLogger = configurationLoader(configuration); // Apply configuration switchableLogger.Set(newLogger, disposePrev: true); } finally { // Monitor next change configuration.GetReloadToken().RegisterChangeCallback(handleReloadContainer[0], services); } }; // Monitor configuration changes configuration.GetReloadToken().RegisterChangeCallback(handleReloadContainer[0], services); // Return builder. return(builder); }
public static IServiceCollection AddBusinessServices(this IServiceCollection services) { ServiceCollectionServiceExtensions.AddScoped <IYetkilimUnitOfWork, YetkilimUnitOfWork>(services); ServiceCollectionServiceExtensions.AddScoped <IPlaceService, PlaceService>(services); ServiceCollectionServiceExtensions.AddScoped <IFeedbackService, FeedbackService>(services); ServiceCollectionServiceExtensions.AddScoped <ICompanyService, CompanyService>(services); ServiceCollectionServiceExtensions.AddScoped <IUserService, UserService>(services); ServiceCollectionServiceExtensions.AddScoped <IPanelUserService, PanelUserService>(services); ServiceCollectionServiceExtensions.AddScoped <IPromotionService, PromotionService>(services); ServiceCollectionServiceExtensions.AddScoped <IEmailSender, EmailSender>(services); ServiceCollectionServiceExtensions.AddScoped <ICompanyFeedbackService, CompanyFeedbackService>(services); return(services); }
public static WebApplicationFactory <TStartup> WithResponse <TStartup, TRequest, TResponse> (this WebApplicationFactory <TStartup> factory, TResponse response) where TStartup : class where TRequest : IRequest <TResponse> => factory.WithWebHostBuilder(c => { c.ConfigureTestServices(srv => { var mediatorMock = new Mock <IMediator>(); mediatorMock .Setup(m => m.Send(It.IsAny <TRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(response); ServiceCollectionServiceExtensions.AddTransient(srv, _ => mediatorMock.Object); }); });
/// <summary> /// Adds a singleton service of the type specified in serviceType with an instance /// specified in implementationInstance to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection. /// </summary> /// <typeparam name="TKey">The type of key.</typeparam> /// <param name="services">The Microsoft.Extensions.DependencyInjection.IServiceCollection /// to add the service to. /// </param> /// <param name="serviceType">The type of the service to register.</param> /// <param name="implementationInstance">The instance of the service.</param> /// <param name="key">A key on which the dependency is registered.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IServiceCollection AddSingleton <TKey>( this IServiceCollection services, Type serviceType, object implementationInstance, TKey key) { services.AddSingleton <INamedServiceEnvelope <TKey> >( provider => new NamedServiceEnvelope <TKey>( key, serviceType, _ => implementationInstance)); ServiceCollectionServiceExtensions.AddSingleton(services, serviceType, implementationInstance); return(services); }
/// <summary> /// Adds a singleton service of the type specified in serviceType with an implementation /// of the type specified in implementationType to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection. /// </summary> /// <typeparam name="TKey">The type of key.</typeparam> /// <param name="services">The Microsoft.Extensions.DependencyInjection.IServiceCollection /// to add the service to. /// </param> /// <param name="serviceType">The type of the service to register.</param> /// <param name="implementationType">The implementation type of the service.</param> /// <param name="key">A key on which the dependency is registered.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IServiceCollection AddSingleton <TKey>( this IServiceCollection services, Type serviceType, Type implementationType, TKey key) { services.AddSingleton <INamedServiceEnvelope <TKey> >( provider => new NamedServiceEnvelope <TKey>( key, serviceType, p => p.GetServices(serviceType).FirstOrDefault(s => s.GetType() == implementationType))); ServiceCollectionServiceExtensions.AddSingleton(services, serviceType, implementationType); return(services); }
/// <summary> /// Adds a singleton service of the type specified in serviceType with a factory /// specified in implementationFactory to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection. /// </summary> /// <typeparam name="TKey">The type of key.</typeparam> /// <param name="services">The Microsoft.Extensions.DependencyInjection.IServiceCollection /// to add the service to. /// </param> /// <param name="serviceType">The type of the service to register.</param> /// <param name="implementationFactory">The factory that creates the service.</param> /// <param name="key">A key on which the dependency is registered.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IServiceCollection AddSingleton <TKey>( this IServiceCollection services, Type serviceType, Func <IServiceProvider, object> implementationFactory, TKey key) { services.AddSingleton <INamedServiceEnvelope <TKey> >( provider => new NamedServiceEnvelope <TKey>( key, serviceType, implementationFactory)); ServiceCollectionServiceExtensions.AddSingleton(services, serviceType, implementationFactory); return(services); }
public static IDataProtectionBuilder PersistKeysToDb(this IDataProtectionBuilder builder, Func <ICacheEntryRepository> factory) { if (builder == null) { throw new ArgumentNullException("builder"); } ServiceCollectionServiceExtensions.AddSingleton <IConfigureOptions <KeyManagementOptions> >(builder.Services, (Func <IServiceProvider, IConfigureOptions <KeyManagementOptions> >) delegate(IServiceProvider services) { return(new ConfigureOptions <KeyManagementOptions>((Action <KeyManagementOptions>) delegate(KeyManagementOptions options) { options.XmlRepository = new XmlRepository(factory); })); }); return(builder); }
public static IServiceCollection AddHostingShellServices(this IServiceCollection services) { dummyVar0 = ServiceCollectionServiceExtensions.AddSingleton <IShellHost, ShellHost>(services); stackVariable2 = services; stackVariable3 = OrchardCore.Environment.Shell.ServiceCollectionExtensions.u003cu003ec.u003cu003e9__0_0; if (stackVariable3 == null) { dummyVar1 = stackVariable3; stackVariable3 = new Func <IServiceProvider, IShellDescriptorManagerEventHandler>(OrchardCore.Environment.Shell.ServiceCollectionExtensions.u003cu003ec.u003cu003e9.u003cAddHostingShellServicesu003eb__0_0); OrchardCore.Environment.Shell.ServiceCollectionExtensions.u003cu003ec.u003cu003e9__0_0 = stackVariable3; } dummyVar2 = ServiceCollectionServiceExtensions.AddSingleton <IShellDescriptorManagerEventHandler>(stackVariable2, stackVariable3); ServiceCollectionDescriptorExtensions.TryAddSingleton <IShellSettingsManager, SingleShellSettingsManager>(services); dummyVar3 = ServiceCollectionServiceExtensions.AddTransient <IConfigureOptions <ShellOptions>, ShellOptionsSetup>(services); dummyVar4 = ServiceCollectionServiceExtensions.AddSingleton <IShellContextFactory, ShellContextFactory>(services); dummyVar5 = ServiceCollectionServiceExtensions.AddSingleton <ICompositionStrategy, CompositionStrategy>(services); dummyVar6 = ServiceCollectionServiceExtensions.AddSingleton <IShellContainerFactory, ShellContainerFactory>(services); dummyVar7 = ServiceCollectionServiceExtensions.AddSingleton <IRunningShellTable, RunningShellTable>(services); return(services); }
/// <summary> /// Adds LiteX SQLite Cache manager services /// </summary> /// <param name="services"></param> /// <param name="options">Option setup.</param> /// <returns></returns> public static IServiceCollection AddLiteXSQLiteCache(this IServiceCollection services, Action <SQLiteConfig> options) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) if (options == null) { throw new ArgumentNullException("options"); } SQLiteConfig sQLiteConfig = new SQLiteConfig(); options(sQLiteConfig); ServiceCollectionServiceExtensions.AddSingleton <SQLiteConfig>(services, sQLiteConfig); services.AddLiteXPerRequestCache(); ServiceCollectionServiceExtensions.AddSingleton <ISQLiteConnectionProvider, SQLiteConnectionProvider>(services); ServiceCollectionServiceExtensions.AddScoped <ILiteXCacheManager, SQLiteCacheManager>(services); ServiceCollectionServiceExtensions.AddScoped <ILiteXCacheManagerAsync, SQLiteCacheManager>(services); return(services); }
public void Configure(JasperRegistry registry) { // Not sure *why* you'd do this, but you could registry.Configuration.AddJsonFile("someFile.json"); // Add service registrations ServiceCollectionServiceExtensions.AddTransient <IFoo, Foo>(registry.Services); // Alter settings within the application registry.Settings.Alter <BusSettings>(_ => { _.JsonSerialization.TypeNameHandling = TypeNameHandling.All; }); // Register additional ASP.Net Core middleware, // but it'd probably be better to use an IStartupFilter // for ordering instead registry.Http.AddSomeMiddleware(); }
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args).ConfigureServices((Action <HostBuilderContext, IServiceCollection>)((hostContext, services) => ServiceCollectionServiceExtensions.AddSingleton <IHostedService>(services, (Func <IServiceProvider, IHostedService>)(serviceProvider => { Tracker tracker = Program.InitTracker(); tracker.PostStats(); return((IHostedService) new TrackerJob(tracker, Program.Logger)); }))));
/// <summary> /// Adds LiteX per http request cache manager services /// Life: Scoped /// </summary> /// <param name="services"></param> /// <returns></returns> public static IServiceCollection AddLiteXPerRequestCache(this IServiceCollection services) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) ServiceCollectionServiceExtensions.AddScoped <ICacheManager, PerRequestCacheManager>(services); return(services); }
public override void Process(IocArgs args) { //TODO patch ServiceCollectionServiceExtensions.AddTransient <IHotspotImageRepository, HotspotImageRepository>(args.ServiceCollection); }
public override void Process(IocArgs args) { ServiceCollectionServiceExtensions.AddTransient <IHistogramRepository, HistogramRepository>(args.ServiceCollection); ServiceCollectionServiceExtensions.AddTransient <IScatterPlotRepository, ScatterPlotRepository>(args.ServiceCollection); ServiceCollectionServiceExtensions.AddTransient <ISunburstRepository, SunburstRepository>(args.ServiceCollection); }
public static void AddUserContextLoader(this IServiceCollection services) { ServiceCollectionServiceExtensions.AddScoped(services, x => x.GetUserContext(new UserContext())); ServiceCollectionServiceExtensions.AddScoped <IUserContextLoader, UserContextLoader>(services); }