Exemplo n.º 1
0
 /// <summary>
 ///     Adds the specified <typeparamref name="TService" /> as a <see cref="ServiceLifetime.Singleton" /> service
 ///     implementation type specified in <typeparamref name="TImplementation" />
 ///     to the <paramref name="services" /> if the service type hasn't already been registered.
 /// </summary>
 /// <typeparam name="TService">The type of the service to add.</typeparam>
 /// <typeparam name="TImplementation">The type of the implementation to use.</typeparam>
 public static IServiceCollection TryAddSingleton <TService, TImplementation>(this IServiceCollection services)
     where TImplementation : class, TService
     where TService : class
 {
     ServiceCollectionDescriptorExtensions.TryAddSingleton <TService, TImplementation>(services);
     return(services);
 }
 /// <inheritdoc cref="ServiceCollectionDescriptorExtensions.TryAddScoped{TService, TImplementation}(IServiceCollection)"/>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IServiceCollection TryAddScoped <TService, TImplementation>(this IServiceCollection collection)
     where TService : class
     where TImplementation : class, TService
 {
     ServiceCollectionDescriptorExtensions.TryAddScoped <TService, TImplementation>(collection);
     return(collection);
 }
 /// <summary>
 /// Registers blazor download file service
 /// </summary>
 /// <param name="services"></param>
 /// <param name="lifetime"></param>
 /// <returns></returns>
 public static IServiceCollection AddBlazorDownloadFile(this IServiceCollection services, ServiceLifetime lifetime = ServiceLifetime.Scoped)
 {
     return(ServiceCollectionDescriptorExtensions.Add(services,
                                                      new ServiceDescriptor(typeof(IBlazorDownloadFileService),
                                                                            sp => new BlazorDownloadFileService(sp.GetRequiredService <IJSRuntime>()),
                                                                            lifetime)));
 }
Exemplo n.º 4
0
		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(// 
Exemplo n.º 5
0
		public void AddCoreServices(IServiceCollection services)
		{
			ServiceCollectionDescriptorExtensions.TryAddScoped<IShellStateUpdater, ShellStateUpdater>(services);
			ServiceCollectionDescriptorExtensions.TryAddScoped<IShellStateManager, NullShellStateManager>(services);
			dummyVar0 = ServiceCollectionServiceExtensions.AddScoped<IShellDescriptorManagerEventHandler, ShellStateCoordinator>(services);
			return;
		}
 public static IServiceCollection AddDistributedNullCache(this IServiceCollection services)
 {
     if (services == null)
     {
         throw new ArgumentNullException("services");
     }
     ServiceCollectionDescriptorExtensions.TryAdd(services, ServiceDescriptor.Singleton <IDistributedCache, NullDistributedCache>());
     return(services);
 }
Exemplo n.º 7
0
        //
        // Summary:
        //     /// Adds a non distributed in memory implementation of BlitzCache
        //     to the /// Microsoft.Extensions.DependencyInjection.IServiceCollection. ///
        //
        // Parameters:
        //   services:
        //     The Microsoft.Extensions.DependencyInjection.IServiceCollection to add services
        //     to.
        //
        // Returns:
        //     The Microsoft.Extensions.DependencyInjection.IServiceCollection so that additional
        //     calls can be chained.
        public static IServiceCollection AddBlitzCache(this IServiceCollection services, long defaultMilliseconds = 60000)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            OptionsServiceCollectionExtensions.AddOptions(services);
            ServiceCollectionDescriptorExtensions.TryAdd(services, ServiceDescriptor.Singleton <IBlitzCache>(new BlitzCache(defaultMilliseconds)));

            return(services);
        }
Exemplo n.º 8
0
        //
        // Summary:
        //     /// Adds PoorMan's Grid FilterService
        //     to the /// Microsoft.Extensions.DependencyInjection.IServiceCollection. ///
        //
        // Parameters:
        //   services:
        //     The Microsoft.Extensions.DependencyInjection.IServiceCollection to add services
        //     to.
        //
        // Returns:
        //     The Microsoft.Extensions.DependencyInjection.IServiceCollection so that additional
        //     calls can be chained.
        public static IServiceCollection AddPoorMansGridFilterService(this IServiceCollection services, TextSearchOption options = TextSearchOption.Default)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            OptionsServiceCollectionExtensions.AddOptions(services);
            ServiceCollectionDescriptorExtensions.TryAdd(services, ServiceDescriptor.Scoped <IFilterService>(s => new FilterService(options)));

            return(services);
        }
 public void Insert(int index, ServiceDescriptor item)
 {
     this._innerServiceCollection.Insert(index, item);
     stackVariable5 = this._currentFeatureServiceCollection;
     if (stackVariable5 == null)
     {
         dummyVar0 = stackVariable5;
         return;
     }
     dummyVar1 = ServiceCollectionDescriptorExtensions.Add(stackVariable5, item);
     return;
 }
 void System.Collections.Generic.ICollection <Microsoft.Extensions.DependencyInjection.ServiceDescriptor> .Add(ServiceDescriptor item)
 {
     this._innerServiceCollection.Add(item);
     stackVariable4 = this._currentFeatureServiceCollection;
     if (stackVariable4 == null)
     {
         dummyVar0 = stackVariable4;
         return;
     }
     dummyVar1 = ServiceCollectionDescriptorExtensions.Add(stackVariable4, item);
     return;
 }
Exemplo n.º 11
0
        public static IMvcBuilder AddMvcCustomer(this IServiceCollection services, string scheme, Action <MvcApplicationOptions> mvcOptions = null)
        {
            ServiceCollectionDescriptorExtensions.Replace(services, ServiceDescriptor.Singleton <IFilterProvider, MvcFilterProvider>());
            var result = services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1).AddJsonOptions(setupAction =>
            {
                setupAction.SerializerSettings.NullValueHandling     = NullValueHandling.Ignore;
                setupAction.SerializerSettings.DateFormatString      = "yyyy-MM-d HH:mm";
                setupAction.SerializerSettings.DateTimeZoneHandling  = DateTimeZoneHandling.Local;
                setupAction.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            });

            services.AddAuthentication(options => options.AddScheme <MvcCookieAuthenticationHandler>(scheme, scheme));
            return(result);
        }
Exemplo n.º 12
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.º 13
0
        public static IServiceCollection AddMessageProcessor <TMessage, TMessageProcessor>(
            this IServiceCollection serviceCollection,
            Action <IServiceProvider, AzureStorageQueueWorkerOptionsBuilder> optionsAction,
            ServiceLifetime serviceLifetime = ServiceLifetime.Scoped,
            bool configureTelemetry         = true,
            bool avoidMessageSampling       = true)
            where TMessageProcessor : IMessageProcessor <TMessage>
        {
            if (!_timeoutConfigured)
            {
                _timeoutConfigured = true;
                serviceCollection.PostConfigure <HostOptions>(o => o.ShutdownTimeout = TimeSpan.FromSeconds(20));
            }

            if (configureTelemetry && !_telemetryConfigured)
            {
                _telemetryConfigured = true;
                serviceCollection.AddApplicationInsightsTelemetryWorkerService();
                serviceCollection.ConfigureTelemetryModule <DependencyTrackingTelemetryModule>((module, o) => { module.EnableSqlCommandTextInstrumentation = true; });
            }

            if (avoidMessageSampling)
            {
                ServiceCollectionDescriptorExtensions
                .Add(
                    serviceCollection,
                    new ServiceDescriptor(
                        typeof(ITelemetryInitializer),
                        CreateAvoidSamplingTelemetryInitializer <TMessageProcessor>,
                        ServiceLifetime.Singleton));
            }

            serviceCollection.TryAdd(
                new ServiceDescriptor(
                    typeof(AzureStorageQueueWorkerOptions <TMessageProcessor>),
                    p => CreateAzureStorageQueueWorkerOptions <TMessage, TMessageProcessor>(p, optionsAction),
                    ServiceLifetime.Singleton));

            serviceCollection.TryAdd(
                new ServiceDescriptor(
                    typeof(TMessageProcessor),
                    typeof(TMessageProcessor),
                    serviceLifetime));

            serviceCollection.AddHostedService <AzureStorageQueueWorker <TMessage, TMessageProcessor> >();

            return(serviceCollection);
        }
        //
        /// <summary>
        /// 创建自定义AddMvc
        /// </summary>
        /// <param name="services"></param>
        /// <param name="mvcOptions"></param>
        /// <returns></returns>
        public static IMvcBuilder AddMvcCustomer(this IServiceCollection services, Action <MvcApplicationOptions> mvcOptions = null)
        {
            ServiceCollectionDescriptorExtensions.Replace(services, ServiceDescriptor.Singleton <IFilterProvider, MvcFilterProvider>());

            var result = services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1).AddJsonOptions(_mvcJsonOptions =>
            {
                _mvcJsonOptions.SerializerSettings.NullValueHandling     = NullValueHandling.Ignore;
                _mvcJsonOptions.SerializerSettings.DateFormatString      = "yyyy-MM-d HH:mm";
                _mvcJsonOptions.SerializerSettings.DateTimeZoneHandling  = DateTimeZoneHandling.Local;
                _mvcJsonOptions.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver();
                _mvcJsonOptions.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            });

            services.AddAuthentication(options => options.AddScheme <MvcCookieAuthenticationHandler>(TbConstant.WEBSITE_AUTHENTICATION_SCHEME, TbConstant.WEBSITE_AUTHENTICATION_SCHEME));

            services.BuildServiceProvider().RegisterServiceProvider();
            return(result);
        }
Exemplo n.º 15
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.º 16
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.TryAddEnumerable(IServiceCollection, ServiceDescriptor)"/>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IServiceCollection TryAddEnumerable(this IServiceCollection collection, ServiceDescriptor descriptor)
 {
     ServiceCollectionDescriptorExtensions.TryAddEnumerable(collection, descriptor);
     return(collection);
 }
Exemplo n.º 18
0
 public override void ConfigureServices(IServiceCollection services)
 {
     base.ConfigureServices(services);
     ServiceCollectionDescriptorExtensions.Replace(services, new ServiceDescriptor(typeof(MongoAccess), dataSourceMock.Object));
 }
Exemplo n.º 19
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);
 }
 /// <inheritdoc cref="ServiceCollectionDescriptorExtensions.TryAddScoped(IServiceCollection, Type, Type)"/>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IServiceCollection TryAddScoped(this IServiceCollection collection, Type service, Type implementationType)
 {
     ServiceCollectionDescriptorExtensions.TryAddScoped(collection, service, implementationType);
     return(collection);
 }
 /// <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.TryAddScoped(IServiceCollection, Type, Func{IServiceProvider, object})"/>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IServiceCollection TryAddScoped(this IServiceCollection collection, Type service, Func <IServiceProvider, object> implementationFactory)
 {
     ServiceCollectionDescriptorExtensions.TryAddScoped(collection, service, implementationFactory);
     return(collection);
 }
 /// <inheritdoc cref="ServiceCollectionDescriptorExtensions.TryAddScoped{TService}(IServiceCollection)"/>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IServiceCollection TryAddScoped <TService>(this IServiceCollection collection)
     where TService : class
 {
     ServiceCollectionDescriptorExtensions.TryAddScoped <TService>(collection);
     return(collection);
 }
 /// <inheritdoc cref="ServiceCollectionDescriptorExtensions.TryAddScoped{TService}(IServiceCollection, Func{IServiceProvider, TService})"/>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IServiceCollection TryAddScoped <TService>(this IServiceCollection collection, Func <IServiceProvider, TService> implementationFactory)
     where TService : class
 {
     ServiceCollectionDescriptorExtensions.TryAddScoped(collection, implementationFactory);
     return(collection);
 }
Exemplo n.º 25
0
 /// <summary>
 ///     Adds the specified <typeparamref name="TService" /> as a <see cref="ServiceLifetime.Singleton" /> service
 ///     using the factory specified in <paramref name="implementationFactory" />
 ///     to the <paramref name="services" /> if the service type hasn't already been registered.
 /// </summary>
 /// <typeparam name="TService">The type of the service to add.</typeparam>
 public static IServiceCollection TryAddSingleton <TService>(this IServiceCollection services, Func <IServiceProvider, TService> implementationFactory)
     where TService : class
 {
     ServiceCollectionDescriptorExtensions.TryAddSingleton(services, implementationFactory);
     return(services);
 }
 public static IServiceCollection AddExtensionManager(this IServiceCollection services)
 {
     ServiceCollectionDescriptorExtensions.TryAddTransient <IFeatureHash, FeatureHash>(services);
     return(services);
 }
 /// <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.TryAdd(IServiceCollection, IEnumerable{ServiceDescriptor})"/>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IServiceCollection TryAdd(this IServiceCollection collection, IEnumerable <ServiceDescriptor> descriptors)
 {
     ServiceCollectionDescriptorExtensions.TryAdd(collection, descriptors);
     return(collection);
 }
Exemplo n.º 29
0
 public static IServiceCollection AddSnailRedisMemoryCache(this IServiceCollection services, Action <RedisCacheOptions> setupAction)
 {
     services.AddStackExchangeRedisCache(setupAction);
     ServiceCollectionDescriptorExtensions.TryAdd(services, ServiceDescriptor.Singleton <ISnailCache, SnailRedisCache>());
     return(services);
 }
 public static IServiceCollection AddSnailMemoryCache(this IServiceCollection services)
 {
     ServiceCollectionDescriptorExtensions.TryAdd(services, ServiceDescriptor.Singleton <ISnailCache, SnailMemoryCache>());
     services.AddMemoryCache();
     return(services);
 }