public static IServiceProvider ConfigureServices(this IServiceCollection services, IConfiguration configuration)
        {
            services.ConfigureInfrastructureServices(configuration);

            var mvcBuilder = services.AddMvcService();

            mvcBuilder.AddMvcOptions(options =>
            {
                options.ModelMetadataDetailsProviders.Add(new EntityDataAnnotationsMetadataProvider());
            });

            var typeFinder = new AppDomainTypeFinder();

            var configureServiceTypes     = typeFinder.FindTypes <IConfigureServices>();
            var configureServiceInstances =
                configureServiceTypes.Select(x => (IConfigureServices)Activator.CreateInstance(x))
                .OrderBy(x => x.Order);

            foreach (var configureService in configureServiceInstances)
            {
                configureService.ConfigureServices(services, configuration);
            }


            var serviceProvider = services.BuildServiceProvider();

            DependencyResolver.Current.SetServiceProvider(serviceProvider);

            return(serviceProvider);
        }
Example #2
0
        public void FindType()
        {
            var typeFinder = new AppDomainTypeFinder();

            var cacheType = typeFinder.FindTypes <ICache>();

            Assert.AreEqual(cacheType.ToList().Count, 2); // memoryCache and RedisCache. 抽象的 EmptyCache 不会被查找。
        }