/// <inheritdoc cref="ServiceCollectionDescriptorExtensions.TryAddSingleton{TService, TImplementation}(IServiceCollection)"/>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IServiceCollection TryAddSingleton <TService, TImplementation>(this IServiceCollection collection)
     where TService : class
     where TImplementation : class, TService
 {
     ServiceCollectionDescriptorExtensions.TryAddSingleton <TService, TImplementation>(collection);
     return(collection);
 }
Exemplo n.º 2
0
 public static ISiloHostBuilder AddRedisGrainStorage(this ISiloHostBuilder builder, string name)
 {
     return(builder.ConfigureApplicationParts(delegate(IApplicationPartManager parts)
     {
         parts.AddFrameworkPart(typeof(RedisGrainStorage).Assembly);
     }).ConfigureServices(delegate(IServiceCollection services)
     {
         services.ConfigureNamedOptionForLogging <MemoryGrainStorageOptions>(name);
         if (string.Equals(name, "Default"))
         {
             ServiceCollectionDescriptorExtensions.TryAddSingleton <IGrainStorage>(services, (Func <IServiceProvider, IGrainStorage>)((IServiceProvider sp) => sp.GetServiceByName <IGrainStorage>("Default")));
         }
         services.AddSingletonNamedService(name, RedisGrainStorageFactory.Create);
     }));
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
        // Big hack, tests fails if only call AddHangfire because Hangfire fail at initializing at the second test run
        private void AddHangfireFix(IServiceCollection services)
        {
            Action <IGlobalConfiguration> configuration = o =>
            {
                var scope   = AspNetCoreJobActivator.Current.BeginScope(null);
                var options = (ApplicationDbContextFactory)scope.Resolve(typeof(ApplicationDbContextFactory));
                options.ConfigureHangfireBuilder(o);
            };

            ServiceCollectionDescriptorExtensions.TryAddSingleton <Action <IGlobalConfiguration> >(services, (IServiceProvider serviceProvider) => new Action <IGlobalConfiguration>((config) =>
            {
                ILoggerFactory service = ServiceProviderServiceExtensions.GetService <ILoggerFactory>(serviceProvider);
                if (service != null)
                {
                    Hangfire.GlobalConfigurationExtensions.UseLogProvider <AspNetCoreLogProvider>(config, new AspNetCoreLogProvider(service));
                }
                IServiceScopeFactory service2 = ServiceProviderServiceExtensions.GetService <IServiceScopeFactory>(serviceProvider);
                if (service2 != null)
                {
                    Hangfire.GlobalConfigurationExtensions.UseActivator <AspNetCoreJobActivator>(config, new AspNetCoreJobActivator(service2));
                }
                configuration(config);
            }));

            services.AddHangfire(configuration);
            services.AddCors(o =>
            {
                o.AddPolicy("BitpayAPI", b =>
                {
                    b.AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
                });
            });

            services.Configure <IOptions <ApplicationInsightsServiceOptions> >(o =>
            {
                o.Value.DeveloperMode = _Env.IsDevelopment();
            });
        }
 /// <inheritdoc cref="ServiceCollectionDescriptorExtensions.TryAddSingleton(IServiceCollection, Type)"/>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IServiceCollection TryAddSingleton(this IServiceCollection collection, Type service)
 {
     ServiceCollectionDescriptorExtensions.TryAddSingleton(collection, service);
     return(collection);
 }
 /// <inheritdoc cref="ServiceCollectionDescriptorExtensions.TryAddSingleton{TService}(IServiceCollection, Func{IServiceProvider, TService})"/>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IServiceCollection TryAddSingleton <TService>(this IServiceCollection collection, Func <IServiceProvider, TService> implementationFactory)
     where TService : class
 {
     ServiceCollectionDescriptorExtensions.TryAddSingleton(collection, implementationFactory);
     return(collection);
 }
 /// <inheritdoc cref="ServiceCollectionDescriptorExtensions.TryAddSingleton{TService}(IServiceCollection, TService)"/>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IServiceCollection TryAddSingleton <TService>(this IServiceCollection collection, TService instance)
     where TService : class
 {
     ServiceCollectionDescriptorExtensions.TryAddSingleton(collection, instance);
     return(collection);
 }
 /// <inheritdoc cref="ServiceCollectionDescriptorExtensions.TryAddSingleton(IServiceCollection, Type, Func{IServiceProvider, object})"/>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IServiceCollection TryAddSingleton(this IServiceCollection collection, Type service, Func <IServiceProvider, object> implementationFactory)
 {
     ServiceCollectionDescriptorExtensions.TryAddSingleton(collection, service, implementationFactory);
     return(collection);
 }
Exemplo n.º 9
0
 /// <summary>
 ///     Adds the specified <paramref name="serviceType" /> as a <see cref="ServiceLifetime.Singleton" /> service
 ///     with the <paramref name="implementationType" /> implementation
 ///     to the <paramref name="services" /> if the service type hasn't already been registered.
 /// </summary>
 public static IServiceCollection TryAddSingleton(this IServiceCollection services, Type serviceType, Type implementationType)
 {
     ServiceCollectionDescriptorExtensions.TryAddSingleton(services, serviceType, implementationType);
     return(services);
 }