public static RddBuilder AddOnSaveChangesHook <TOnSaveChanges, T>(this RddBuilder rddBuilder)
     where TOnSaveChanges : class, IOnSaveChangesHookAsync <T>
     where T : class
 {
     rddBuilder.Services.AddScoped <IUnitOfWork, EventProcessableUnitOfWork>();
     rddBuilder.Services.AddScoped <ISaveEventProcessor, SaveEventProcessor <T> >();
     rddBuilder.Services.AddScoped <IOnSaveChangesHookAsync <T>, TOnSaveChanges>();
     return(rddBuilder);
 }
        public static RddBuilder AddReadOnlyRepository <TRepository, TEntity>(this RddBuilder rddBuilder)
            where TRepository : class, IReadOnlyRepository <TEntity>
            where TEntity : class
        {
            rddBuilder.Services
            .AddScoped <IReadOnlyRepository <TEntity>, TRepository>(s => s.GetRequiredService <TRepository>())
            .AddScoped <TRepository>();

            return(rddBuilder);
        }
        public static RddBuilder AddPatcher <TPatcher, T>(this RddBuilder rddBuilder)
            where TPatcher : class, IPatcher <T>
            where T : class
        {
            rddBuilder.Services
            .AddSingleton <IPatcher <T>, TPatcher>(s => s.GetRequiredService <TPatcher>())
            .AddSingleton <TPatcher>();

            return(rddBuilder);
        }
 private static RddBuilder ApplyRddSetupOptions(this RddBuilder rddBuilder)
 {
     rddBuilder.Services.PostConfigure <MvcNewtonsoftJsonOptions>(o =>
     {
         foreach (JsonConverter converter in rddBuilder.JsonConverters)
         {
             o.SerializerSettings.Converters.Add(converter);
         }
     });
     return(rddBuilder);
 }
        public static RddBuilder AddRestCollection <TCollection, TEntity, TKey>(this RddBuilder rddBuilder)
            where TCollection : class, IRestCollection <TEntity, TKey>
            where TEntity : class, IEntityBase <TKey>
            where TKey : IEquatable <TKey>
        {
            rddBuilder.Services
            .AddScoped <IRestCollection <TEntity, TKey>, TCollection>(s => s.GetRequiredService <TCollection>())
            .AddScoped <IReadOnlyRestCollection <TEntity, TKey>, TCollection>(s => s.GetRequiredService <TCollection>())
            .AddScoped <TCollection>();

            return(rddBuilder);
        }
        public static RddBuilder AddAppController <TController, TEntity, TKey>(this RddBuilder rddBuilder)
            where TController : class, IAppController <TEntity, TKey>
            where TEntity : class, IEntityBase <TKey>
            where TKey : IEquatable <TKey>
        {
            rddBuilder.Services
            .AddScoped <IAppController <TEntity, TKey>, TController>(s => s.GetRequiredService <TController>())
            .AddScoped <IReadOnlyAppController <TEntity, TKey>, TController>(s => s.GetRequiredService <TController>())
            .AddScoped <TController>();

            return(rddBuilder);
        }
        public static RddBuilder WithDefaultRights(this RddBuilder rddBuilder, RightDefaultMode mode)
        {
            switch (mode)
            {
            case RightDefaultMode.Closed:
                rddBuilder.Services.AddSingleton(typeof(IRightExpressionsHelper <>), typeof(ClosedRightExpressionsHelper <>));
                break;

            case RightDefaultMode.Open:
                rddBuilder.Services.AddSingleton(typeof(IRightExpressionsHelper <>), typeof(OpenRightExpressionsHelper <>));
                break;

            default:
                throw new ArgumentException("Invalid right mode", nameof(mode));
            }
            return(rddBuilder);
        }
        public static RddBuilder AddInheritanceConfiguration <TConfig, TEntity, TKey>(this RddBuilder rddBuilder, TConfig config)
            where TConfig : class, IInheritanceConfiguration <TEntity>
            where TEntity : class, IEntityBase <TKey>
            where TKey : IEquatable <TKey>
        {
            var services = rddBuilder.Services;

            services.AddSingleton <IInheritanceConfiguration>(s => config);
            services.AddSingleton <IInheritanceConfiguration <TEntity> >(s => config);

            services.TryAddSingleton <IPatcher <TEntity>, BaseClassPatcher <TEntity> >();
            services.TryAddSingleton <IInstanciator <TEntity>, BaseClassInstanciator <TEntity> >();

            rddBuilder.AddJsonConverter(new BaseClassJsonConverter <TEntity>(config));

            return(rddBuilder);
        }
 private static RddBuilder AddJsonConverter(this RddBuilder rddBuilder, JsonConverter jsonConverter)
 {
     rddBuilder.JsonConverters.Add(jsonConverter);
     return(rddBuilder);
 }