当前位置: 首页>>代码示例>>C#>>正文


C# IServiceCollection.Add方法代码示例

本文整理汇总了C#中IServiceCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.Add方法的具体用法?C# IServiceCollection.Add怎么用?C# IServiceCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IServiceCollection的用法示例。


在下文中一共展示了IServiceCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddLogging();

            services.Add(new ServiceDescriptor(typeof(ISeriesLogic), typeof(SeriesLogic.SeriesLogic), ServiceLifetime.Transient));
            services.Add(new ServiceDescriptor(typeof(ISeriesCache), typeof(InMemoryCache), ServiceLifetime.Singleton));
            services.Add(new ServiceDescriptor(typeof(ISeriesEvaluator), typeof(FibonacciSeriesEvaluator), ServiceLifetime.Transient));
            services.Add(new ServiceDescriptor(typeof(ISeriesEvaluator), typeof(PrimeSeriesEvaluator), ServiceLifetime.Transient));
        }
开发者ID:EugeneKrapivin,项目名称:SeriesService,代码行数:10,代码来源:Startup.cs

示例2: Configure

        public void Configure(IServiceCollection serviceCollection)
        {
            // MVC is already registering IMemoryCache as host singleton. We are registering it again
            // in this module so that there is one instance for each tenant.
            serviceCollection.Add(ServiceDescriptor.Singleton<IMemoryCache, MemoryCache>());


            // LocalCache is registered as transient as its implementation resolves IMemoryCache, thus
            // there is no state to keep in its instance.
            serviceCollection.Add(ServiceDescriptor.Transient<IDistributedCache, MemoryDistributedCache>());
        }
开发者ID:geertdoornbos,项目名称:Orchard2,代码行数:11,代码来源:DefaultMemoryCache.cs

示例3: ConfigureServices

 // This method gets called by the runtime.
 public void ConfigureServices(IServiceCollection services)
 {
     // Add MVC services to the services container.
     services.AddMvc();
     var d = new ServiceDescriptor(typeof(IUnitOfWork), new UnitOfWork());
     services.Add(d);
 }
开发者ID:LeoLcy,项目名称:MVC6Recipes,代码行数:8,代码来源:Startup.cs

示例4: Register

 public void Register(IServiceCollection serviceCollection)
 {
     foreach (var service in _serviceCollection)
     {
         serviceCollection.Add(service);
     }
 }
开发者ID:skimur,项目名称:skimur,代码行数:7,代码来源:ServiceCollectionRegistrar.cs

示例5: Configure

        public void Configure(IServiceCollection serviceCollection)
        {
            // MVC is already registering IMemoryCache. Any module that would add another implementation
            // would take over the default one as the last registered service will be resolved.
            // serviceCollection.Add(ServiceDescriptor.Singleton<IMemoryCache, MemoryCache>());


            // LocalCache is registered as Transient as its implementation resolves IMemoryCache, thus
            // there is no state to keep in its instance.
            serviceCollection.Add(ServiceDescriptor.Transient<IDistributedCache, LocalCache>());
        }
开发者ID:OnefoursevenLabs,项目名称:Orchard2,代码行数:11,代码来源:DefaultMemoryCache.cs

示例6: MergeServiceDescriptions

        private static void MergeServiceDescriptions(IServiceCollection serviceCollection, IEnumerable<ServiceDescriptor> serviceDescriptors)
        {
            var excludedServiceDescriptors = serviceCollection.Where(service => serviceDescriptors.Contains(service) == false);
            foreach (var descriptor in excludedServiceDescriptors)
            {
                serviceCollection.Remove(descriptor);
            }

            foreach (var descriptor in serviceDescriptors)
            {
                serviceCollection.Add(descriptor);
            }
        }
开发者ID:app-enhance,项目名称:ae-di,代码行数:13,代码来源:IServiceCollectionExtensions.cs

示例7: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //This can be injected to any service, controller...
            services.Add(
                new ServiceDescriptor(
                    typeof (IOptions<RedisCacheOptions>),
                    Configuration.Get<RedisCacheOptions>("RedisCacheOptions")
                    )
                );

            //At the moment the redis cache implements the wrong interface, that's why the OwnRedisCache
            services.AddSingleton<IDistributedCache, OwnRedisCache>();
            services.AddSession(o => { o.IdleTimeout = TimeSpan.FromMinutes(15); });

            services.AddMvc();
        }
开发者ID:joaquin-corchero,项目名称:MVC6RedisSessionAndCache,代码行数:17,代码来源:Startup.cs

示例8: RegisterAssembly

        public void RegisterAssembly(IServiceCollection services, AssemblyName assemblyName, string path = "")
        {
            var loadContext = PlatformServices.Default.AssemblyLoadContextAccessor.Default;
            var loader = new DirectoryLoader(path, loadContext);

            var assembly = loader.Load(assemblyName);
            foreach (var type in assembly.DefinedTypes)
            {
                var dependencyAttributes = type.GetCustomAttributes<DependencyAttribute>();
                // Each dependency can be registered as various types
                foreach (var serviceDescriptor in dependencyAttributes.Select(dependencyAttribute => dependencyAttribute.BuiildServiceDescriptor(type)))
                {
                    services.Add(serviceDescriptor);
                }
            }
        }
开发者ID:acotterell1973,项目名称:VN.Task.Manager,代码行数:16,代码来源:RegisterDependencyType.cs

示例9: WireUpDbContexts

        private static void WireUpDbContexts(IServiceCollection services, IConfiguration configuration)
        {
            var cmsConnString = configuration["Data:cmsconnection:ConnectionString"];
            var authConnString = configuration["Data:authconnection:ConnectionString"];

            var connectionStrings = new Dictionary<Type, string>
            {
                {typeof (AuthDbContext), authConnString},
                {typeof (ElmahDbContext), cmsConnString},
                {typeof (ComponentsDbContext), cmsConnString}
            };

            var serviceDescriptor = new ServiceDescriptor(typeof(IDbContextFactory), new DbContextFactory(connectionStrings));
            services.Add(serviceDescriptor);

            services.AddSingleton<IDbContextScopeFactory, DbContextScopeFactory>();
            services.AddSingleton<IAmbientDbContextLocator, AmbientDbContextLocator>();
        }
开发者ID:mitsbits,项目名称:Ubik.MVC5,代码行数:18,代码来源:IoCConfig.cs

示例10: Populate

        public void Populate(IServiceCollection services)
        {
            foreach (var type in Types)
            {
                var typeInfo = type.GetTypeInfo();

                var attribute = typeInfo.GetCustomAttribute<ServiceDescriptorAttribute>();

                if (attribute == null)
                {
                    continue;
                }

                var serviceType = attribute.ServiceType ?? type;

                var descriptor = new ServiceDescriptor(serviceType, type, attribute.Lifetime);

                services.Add(descriptor);
            }
        }
开发者ID:adamhathcock,项目名称:Scrutor,代码行数:20,代码来源:AttributeSelector.cs

示例11: Register

 internal static void Register(IServiceCollection serviceCollection)
 {
     serviceCollection.Add(ServiceDescriptor.Singleton(new DataActionTokenResolver()));
 }
开发者ID:Orckestra,项目名称:C1-CMS,代码行数:4,代码来源:DataActionTokenResolverRegistry.cs

示例12: TryAddMultiRegistrationService

        // Adds a service if the service type and implementation type hasn't been added yet. This is needed for
        // services like IConfigureOptions<MvcOptions> or IApplicationModelProvider where you need the ability
        // to register multiple implementation types for the same service type.
        private static bool TryAddMultiRegistrationService(IServiceCollection services, ServiceDescriptor descriptor)
        {
            // This can't work when registering a factory or instance, you have to register a type.
            // Additionally, if any existing registrations use a factory or instance, we can't check those, but we don't
            // assert that because it might be added by user-code.
            Debug.Assert(descriptor.ImplementationType != null);

            if (services.Any(d =>
                d.ServiceType == descriptor.ServiceType &&
                d.ImplementationType == descriptor.ImplementationType))
            {
                return false;
            }

            services.Add(descriptor);
            return true;
        }
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:20,代码来源:MvcCoreServiceCollectionExtensions.cs

示例13: AddTypeWithInterfaces

 /// <summary>
 /// 以类型实现的接口进行服务添加,需排除
 /// <see cref="ITransientDependency"/>、
 /// <see cref="IScopeDependency"/>、
 /// <see cref="ISingletonDependency"/>、
 /// <see cref="IDependency"/>、
 /// <see cref="IDisposable"/>等非业务接口,如无接口则注册自身
 /// </summary>
 /// <param name="services">服务映射信息集合</param>
 /// <param name="implementationTypes">要注册的实现类型集合</param>
 /// <param name="lifetime">注册的生命周期类型</param>
 protected virtual void AddTypeWithInterfaces(IServiceCollection services, Type[] implementationTypes, LifetimeStyle lifetime)
 {
     foreach (Type implementationType in implementationTypes)
     {
         if (implementationType.IsAbstract || implementationType.IsInterface)
         {
             continue;
         }
         Type[] interfaceTypes = GetImplementedInterfaces(implementationType);
         if (interfaceTypes.Length == 0)
         {
             services.Add(implementationType, implementationType, lifetime);
             continue;
         }
         foreach (Type interfaceType in interfaceTypes)
         {
             services.Add(interfaceType, implementationType, lifetime);
         }
     }
 }
开发者ID:BiaoLiu,项目名称:osharp,代码行数:31,代码来源:ServicesBuilder.cs

示例14: ConfigureServices

 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc();
     var descriptor = new ServiceDescriptor(typeof(IHitCounterService), new HitCounterService(_rootPath));
     services.Add(descriptor);
 }
开发者ID:johnciliberti,项目名称:MVC6Recipes,代码行数:6,代码来源:Startup.cs

示例15: ConfigureServices

        // This method gets called by the runtime.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add EF services to the services container.
            //services.AddEntityFramework(Configuration)
            //    .AddSqlServer()
            //    .AddDbContext<MoBContext>();

            //// Add Identity services to the services container.
            //services.AddIdentity<ApplicationUser, IdentityRole>(Configuration)
            //    .AddEntityFrameworkStores<MoBContext>();

            var d = new ServiceDescriptor(typeof(IUnitOfWork), new UnitOfWork());
            services.Add(d);
            // Add MVC services to the services container.
            services.AddMvc();
        }
开发者ID:LeoLcy,项目名称:MVC6Recipes,代码行数:17,代码来源:Startup.cs


注:本文中的IServiceCollection.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。