/// <summary> /// Register Coddee dynamic API. /// </summary> public static IServiceCollection AddDynamicApi(this IServiceCollection services, Action <DynamicApiConfigurations> config, IEnumerable <Type> controllers) { var serviceProvider = services.BuildServiceProvider(); var container = serviceProvider.GetService <IContainer>(); var manager = new DynamicApiControllersManager(container); DynamicApiConfigurations configInstance = DynamicApiConfigurations.Default(); config?.Invoke(configInstance); container.RegisterInstance(configInstance); controllers.ForEach(manager.RegisterController); container.RegisterInstance(manager); var api = new DynamicApi(container); api.CacheActions(); container.RegisterInstance(api); return(services); }
/// <inheritdoc /> public DynamicApi(IContainer container) { _configurations = container.Resolve <DynamicApiConfigurations>(); _dateTimeConverter = new IsoDateTimeConverter { DateTimeFormat = _configurations.DateTimeFormat }; _jsonSerializer = new JsonSerializerSettings { DateFormatString = _configurations.DateTimeFormat }; _pagesProvider = new PagesProvider(); _cache = new ApiActionsCache(); _parser = new DynamicApiParametersParser(_dateTimeConverter); _authorizationValidator = _configurations.AuthorizationValidator; _repositoryActionLoactor = new RepositoryActionLoactor(); if (container.IsRegistered <DynamicApiControllersManager>()) { _controllersManager = container.Resolve <DynamicApiControllersManager>(); } if (container.IsRegistered <IRepositoryManager>()) { _repositoryManager = container.Resolve <IRepositoryManager>(); } if (container.IsRegistered <ILogger>()) { var logger = container.Resolve <ILogger>(); if (logger is LogAggregator logAggregator) { _logger = logAggregator; } } else { _logger = new LogAggregator(); } }