ServiceCollectionExtensions

Namespace: Omnia.Fx.NetCore
We found 10 examples in language CSharp for this search. You will see 26 fragments of code.
        [Test, CustomAutoMoqData]
        public void ServiceCollection_is_returned(IServiceCollection services, Action<INybusConfigurator> configuratorDelegate)
        {
            var result = ServiceCollectionExtensions.AddNybus(services, configuratorDelegate);

            Assert.That(result, Is.SameAs(services));
        }

        [Test, CustomAutoMoqData]
        public void AddNybus_invokes_configuratorDelegate(IServiceCollection services, Action<INybusConfigurator> configuratorDelegate)
        {
            ServiceCollectionExtensions.AddNybus(services, configuratorDelegate);

            Mock.Get(configuratorDelegate).Verify(p => p(It.IsAny<INybusConfigurator>()));
        }

        [Test, CustomAutoMoqData]
        public void AddNybus_registers_NybusHostOptions(IServiceCollection services, IConfigurationSection configuration, Action<INybusConfigurator> configuratorDelegate)
        {
            ServiceCollectionExtensions.AddNybus(services, configuratorDelegate);

            Mock.Get(services).Verify(p => p.Add(It.Is<ServiceDescriptor>(sd => sd.ServiceType == typeof(NybusHostOptions))));
        }

        [Test, AutoMoqData]
        public void AddCommandHandler_registers_handler_generic_syntax(IServiceCollection services)
        {
            ServiceCollectionExtensions.AddCommandHandler<FirstTestCommand, FirstTestCommandHandler>(services);

            Mock.Get(services).Verify(p => p.Add(It.Is<ServiceDescriptor>(sd => sd.ServiceType == typeof(ICommandHandler<FirstTestCommand>) && sd.ImplementationType == typeof(FirstTestCommandHandler))));
        }

        [Test, AutoMoqData]
        public void AddCommandHandler_registers_handler_by_its_type(IServiceCollection services)
        {
            ServiceCollectionExtensions.AddCommandHandler(services, typeof(FirstTestCommandHandler));

            Mock.Get(services).Verify(p => p.Add(It.Is<ServiceDescriptor>(sd => sd.ServiceType == typeof(ICommandHandler<FirstTestCommand>) && sd.ImplementationType == typeof(FirstTestCommandHandler))));
        }

        [Test, AutoMoqData]
        public void AddCommandHandler_registers_handler_by_its_type_generic_syntax(IServiceCollection services)
        {
            ServiceCollectionExtensions.AddCommandHandler<FirstTestCommandHandler>(services);

            Mock.Get(services).Verify(p => p.Add(It.Is<ServiceDescriptor>(sd => sd.ServiceType == typeof(ICommandHandler<FirstTestCommand>) && sd.ImplementationType == typeof(FirstTestCommandHandler))));
        }

        /// <summary>
        /// Add core project to the service collection.
        /// </summary>
        /// <param name="service">IServiceCollection.</param>
        /// <returns>Updated IServiceCollection.</returns>
        public static IServiceCollection AddAppApplication(this IServiceCollection service)
        {
            service.AddMediatR(typeof(ServiceCollectionExtensions));
            return service;
        }

        [Test, CustomAutoData]
        public void AddWcfService_returns_same_ServiceCollection(IServiceCollection services, WcfServiceConfigurator<TestService> configurator, ServiceLifetime lifetime)
        {
            var result = ServiceCollectionExtensions.AddWcfService<TestService>(services, configurator, lifetime);

            Assert.That(result, Is.SameAs(services));
        }

        [Test, CustomAutoData]
        public void AddWcfService_registers_hosted_service(IServiceCollection services, WcfServiceConfigurator<TestService> configurator, ServiceLifetime lifetime)
        {
            ServiceCollectionExtensions.AddWcfService<TestService>(services, configurator, lifetime);

            Mock.Get(services).Verify(p => p.Add(It.Is<ServiceDescriptor>(d => d.ServiceType == typeof(IHostedService) && d.Lifetime == ServiceLifetime.Singleton)));
        }

        [Test, CustomAutoData]
        public void AddWcfService_registers_announcement_service(IServiceCollection services, WcfServiceConfigurator<TestService> configurator, ServiceLifetime lifetime)
        {
            ServiceCollectionExtensions.AddWcfService<TestService>(services, configurator, lifetime);

            Mock.Get(services).Verify(p => p.Add(It.Is<ServiceDescriptor>(d => d.ServiceType == typeof(IAnnouncementService) && d.Lifetime == ServiceLifetime.Singleton)));
        }

        [Test, CustomAutoData]
        public void AddWcfService_throws_if_same_service_registered_twice(ServiceCollection services, WcfServiceConfigurator<TestService> configurator, ServiceLifetime lifetime)
        {
            ServiceCollectionExtensions.AddWcfService<TestService>(services, configurator, lifetime);

            Assert.Throws<ArgumentException>(() => ServiceCollectionExtensions.AddWcfService<TestService>(services, configurator, lifetime));
        }

        [Test, CustomAutoData]
        public void AddDiscovery_returns_service_collection(IServiceCollection services, Uri announcementUri, TimeSpan interval, Action<TestHttpBinding> configureBinding)
        {
            var result = ServiceCollectionExtensions.AddDiscovery(services, announcementUri, interval, configureBinding);

            Assert.That(result, Is.SameAs(services));
        }

        [Test, CustomAutoData]
        public void AddDiscovery_configures_binding_with_delegate(IServiceCollection services, Uri announcementUri, TimeSpan interval, Action<TestBinding> configureBinding)
        {
            var result = ServiceCollectionExtensions.AddDiscovery(services, announcementUri, interval, configureBinding);

            Mock.Get(configureBinding).Verify(p => p(It.IsAny<TestBinding>()));
        }

        /// <summary>
        /// Add application project to the service collection.
        /// </summary>
        /// <param name="service">IServiceCollection.</param>
        /// <returns>Updated IServiceCollection.</returns>
        public static IServiceCollection AddApplication(this IServiceCollection service)
        {
            service.AddMediatR(typeof(ServiceCollectionExtensions));
            return service;
        }

        /// <summary>
        /// Add Infrastructure project to the service collection.
        /// </summary>
        /// <param name="service">IServiceCollection.</param>
        /// <returns>Updated IServiceCollection.</returns>
        public static IServiceCollection AddInfrastructure(this IServiceCollection service)
        {
            service.AddMediatR(typeof(ServiceCollectionExtensions));
            service.AddHttpClient();
            return service;
        }


        public static IServiceCollection AddQueryHandlers(this IServiceCollection services)
        {

            services.Scan(scan => scan
            .FromAssembliesOf(typeof(ServiceCollectionExtensions))
            .AddClasses(classes => classes.AssignableToAny(typeof(IHandleQueryAsync<,>)))
            .AsImplementedInterfaces()
            .WithTransientLifetime());


            return services;
        }

        public static IServiceCollection AddCommandHandlers(this IServiceCollection services)
        {

            services.Scan(scan => scan
                .FromAssembliesOf(typeof(ServiceCollectionExtensions))
                .AddClasses(classes => classes.AssignableToAny(typeof(IAsyncCommandHandler<,>)))
                .AsImplementedInterfaces()
                .WithTransientLifetime()
                );


            return services;
        }


        public static ISitecoreService BuildSitecoreContextService()
        {
            var sitecoreServiceThunk = ServiceCollectionExtensions.Get<Func<Database, ISitecoreService>>();
            return sitecoreServiceThunk(Sitecore.Context.Database);
        }

        public static IRequestContext BuildRequestContext()
        {
            return new RequestContext(ServiceCollectionExtensions.Get<ISitecoreService>());
        }

        public static IGlassHtml BuildGlassHtml()
        {
            return new GlassHtml(ServiceCollectionExtensions.Get<ISitecoreService>());
        }

        public static IMvcContext BuildMvcContext()
        {
            return new MvcContext(ServiceCollectionExtensions.Get<ISitecoreService>(), ServiceCollectionExtensions.Get<IGlassHtml>());
        }

        private static void Main(string[] args)
        {
            Host.CreateDefaultBuilder().ConfigureServices((context, services) =>
            {
                services.AddMediatR(config =>
                {
                    config.Using<Mediator>().AsScoped();
                }, typeof(ServiceCollectionExtensions));
                services.AddImageProcessing(context.Configuration);
                services.AddHostedService<TestRunner>();
            }).Build().Run();
        }

        public static IServiceCollection AddDb(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddDbContext<ProfilingSampleDbContext>(options =>
            {
                options.UseNpgsql(configuration.GetConnectionString(nameof(ProfilingSampleDbContext)));
            });
            return services;
        }

        public static IServiceCollection AddConfiguredMvc(this IServiceCollection services)
        {
            services
                .AddMvc()
                .AddApplicationPart(typeof(ServiceCollectionExtensions).Assembly)
                .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            return services;
        }


        public static IServiceCollection AddQueryHandlers(this IServiceCollection services)
        {

            services.Scan(scan => scan
            .FromAssembliesOf(typeof(ServiceCollectionExtensions))
            .AddClasses(classes => classes.AssignableToAny(typeof(IHandleQueryAsync<,>)))
            .AsImplementedInterfaces()
            .WithTransientLifetime());


            return services;
        }

        public static IServiceCollection AddCommandHandlers(this IServiceCollection services)
        {

            services.Scan(scan => scan
                .FromAssembliesOf(typeof(ServiceCollectionExtensions))
                .AddClasses(classes => classes.AssignableToAny(typeof(IAsyncCommandHandler<,>)))
                .AsImplementedInterfaces()
                .WithTransientLifetime()
                );


            return services;
        }

Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions : Object

Methods :

public static Void AddOmniaSqlDBContext(IServiceCollection serviceCollection = , Guid sqlResource = , DatabaseContextFactoryFunction<T> dbContextFactory = , ServiceLifetime contextLifetime = Scoped, ServiceLifetime optionsLifetime = Scoped)
public static Void AddOmniaSqlServerDistributedCache(IServiceCollection serviceCollection = , Guid sqlResource = , Action<SqlServiceResource, SqlServerCacheOptions> setupAction = )
public static Void AddOmniaDistributedLock(IServiceCollection serviceCollection = , Guid sqlResourceId = )
public static IServiceCollection AddAsOption(IServiceCollection serviceCollection = )
public static IServiceCollection AddAsOption(IServiceCollection serviceCollection = , Boolean useDefaultBinderAsFallback = , JsonSerializerSettings settingsUsedForSchemaCheckEtc = null)
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()