public static void AddEntityPersistor(this NakedCoreOptions coreOptions, Action <EntityPersistorOptions> setupAction) { var options = new EntityPersistorOptions(); setupAction(options); coreOptions.Services.AddSingleton <IEntityObjectStoreConfiguration>(p => EntityObjectStoreConfiguration(p.GetService <IConfiguration>(), options)); coreOptions.Services.AddScoped <EntityOidGenerator, EntityOidGenerator>(); coreOptions.Services.AddScoped <IOidGenerator, EntityOidGenerator>(); coreOptions.Services.AddScoped <IObjectStore, EntityObjectStore>(); }
private static EntityObjectStoreConfiguration EntityObjectStoreConfiguration(IConfiguration configuration, EntityPersistorOptions options) { var config = new EntityObjectStoreConfiguration { EnforceProxies = options.EnforceProxies, CustomConfig = options.CustomConfig, DefaultMergeOption = options.DefaultMergeOption, MaximumCommitCycles = options.MaximumCommitCycles, NotPersistedTypes = options.NotPersistedTypes, RollBackOnError = options.RollBackOnError, RequireExplicitAssociationOfTypes = options.RequireExplicitAssociationOfTypes }; var contexts = options.ContextInstallers.Select <Func <IConfiguration, DbContext>, Func <DbContext> >(f => () => f(configuration)); contexts.ForEach(c => config.UsingContext(c)); return(config); }