protected override void Setup(FeatureConfigurationContext context) { // Check to see if the user provided us with a shared session to work with before we go and create our own to inject into the pipeline var getAsyncSessionFunc = context.Settings.GetOrDefault <Func <IDictionary <string, string>, IAsyncDocumentSession> >(SharedAsyncSession); if (getAsyncSessionFunc != null) { IOpenTenantAwareRavenSessions sessionCreator = new OpenRavenSessionByCustomDelegate(getAsyncSessionFunc); context.Services.AddSingleton(sessionCreator); context.Settings.AddStartupDiagnosticsSection( StartupDiagnosticsSectionName, new { HasSharedAsyncSession = true, }); } else { context.Services.AddSingleton <IOpenTenantAwareRavenSessions>(sp => { var store = DocumentStoreManager.GetDocumentStore <StorageType.Sagas>(context.Settings, sp); var storeWrapper = new DocumentStoreWrapper(store); var dbNameConvention = context.Settings.GetOrDefault <Func <IDictionary <string, string>, string> >(MessageToDatabaseMappingConvention); return(new OpenRavenSessionByDatabaseName(storeWrapper, dbNameConvention)); }); context.Settings.AddStartupDiagnosticsSection( StartupDiagnosticsSectionName, new { HasSharedAsyncSession = false, HasMessageToDatabaseMappingConvention = context.Settings.HasSetting(MessageToDatabaseMappingConvention), }); } var sessionHolder = new CurrentSessionHolder(); context.Services.AddScoped(_ => sessionHolder.Current); context.Pipeline.Register(new CurrentSessionBehavior(sessionHolder), "Manages the lifecycle of the current session holder."); context.Services.AddSingleton <ISynchronizedStorage, RavenDBSynchronizedStorage>(provider => new RavenDBSynchronizedStorage(provider.GetService <IOpenTenantAwareRavenSessions>(), sessionHolder)); context.Services.AddSingleton <ISynchronizedStorageAdapter>(new RavenDBSynchronizedStorageAdapter(sessionHolder)); }
public Scope(CurrentSessionHolder sessionHolder) { this.sessionHolder = sessionHolder; }
public RavenDBSynchronizedStorageAdapter(CurrentSessionHolder sessionHolder) { this.sessionHolder = sessionHolder; }
public CurrentSessionBehavior(CurrentSessionHolder currentSessionHolder) { this.currentSessionHolder = currentSessionHolder; }
public RavenDBSynchronizedStorage(IOpenTenantAwareRavenSessions sessionCreator, CurrentSessionHolder sessionHolder) { this.sessionCreator = sessionCreator; this.sessionHolder = sessionHolder; }