Beispiel #1
0
        private IDependencyResolver ConfigureIocResolver()
        {
            // Setup configuration for IOC container here
            var config = new IocConfiguration();

            config.CacheType       = GetCacheManagerType();
            config.RegexStringList = GetLoggingRegularExpressionList();
            var iocContainer = new IocContainer(config);

            var controllerTypes = Assembly.GetExecutingAssembly().GetExportedTypes()
                                  .Where(t => !t.IsAbstract && !t.IsGenericTypeDefinition)
                                  .Where(t => typeof(ApiController).IsAssignableFrom(t) || t.Name.EndsWith("Controller", StringComparison.OrdinalIgnoreCase));

            foreach (var type in controllerTypes)
            {
                iocContainer.Services.AddTransient(type);
            }

            var iocResolver = new DefaultDependencyResolver(iocContainer.BuildServiceProvider());

            return(iocResolver);
        }