protected override void Setup(FeatureConfigurationContext context)
        {
            context.Container.ConfigureComponent <RavenDBSynchronizedStorageAdapter>(DependencyLifecycle.SingleInstance);
            context.Container.ConfigureComponent <RavenDBSynchronizedStorage>(DependencyLifecycle.SingleInstance);

            IOpenRavenSessionsInPipeline sessionCreator;

            // 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> >(RavenDbSettingsExtensions.SharedAsyncSessionSettingsKey);
            var getAsyncSessionFuncObsolete = context.Settings.GetOrDefault <Func <IAsyncDocumentSession> >(RavenDbSettingsExtensions.SharedAsyncSessionSettingsKey + ".Obsolete");

            if (getAsyncSessionFunc != null)
            {
                sessionCreator = new OpenRavenSessionByCustomDelegate(getAsyncSessionFunc);
            }
            else if (getAsyncSessionFuncObsolete != null)
            {
                sessionCreator = new OpenRavenSessionByCustomDelegate(getAsyncSessionFuncObsolete);
            }
            else
            {
                var store        = DocumentStoreManager.GetDocumentStore <StorageType.Sagas>(context.Settings);
                var storeWrapper = new DocumentStoreWrapper(store);

                var dbNameConvention = context.Settings.GetOrDefault <Func <IDictionary <string, string>, string> >("RavenDB.SetMessageToDatabaseMappingConvention");
                sessionCreator = new OpenRavenSessionByDatabaseName(storeWrapper, dbNameConvention);
            }

            context.Container.RegisterSingleton(sessionCreator);
            context.Pipeline.Register("OpenRavenDbAsyncSession", new OpenAsyncSessionBehavior(sessionCreator), "Makes sure that there is a RavenDB IAsyncDocumentSession available on the pipeline");
        }
        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));
        }
Exemple #3
0
        protected override void Setup(FeatureConfigurationContext context)
        {
            context.Container.ConfigureComponent <RavenDBSynchronizedStorageAdapter>(DependencyLifecycle.SingleInstance);
            context.Container.ConfigureComponent <RavenDBSynchronizedStorage>(DependencyLifecycle.SingleInstance);

            // 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.Container.RegisterSingleton(sessionCreator);

                context.Settings.AddStartupDiagnosticsSection(
                    StartupDiagnosticsSectionName,
                    new
                {
                    HasSharedAsyncSession = true,
                });
            }
            else
            {
                context.Container.ConfigureComponent <IOpenTenantAwareRavenSessions>(
                    builder =>
                {
                    var store            = DocumentStoreManager.GetDocumentStore <StorageType.Sagas>(context.Settings, builder);
                    var storeWrapper     = new DocumentStoreWrapper(store);
                    var dbNameConvention = context.Settings.GetOrDefault <Func <IDictionary <string, string>, string> >(MessageToDatabaseMappingConvention);
                    return(new OpenRavenSessionByDatabaseName(storeWrapper, dbNameConvention));
                },
                    DependencyLifecycle.SingleInstance);

                context.Settings.AddStartupDiagnosticsSection(
                    StartupDiagnosticsSectionName,
                    new
                {
                    HasSharedAsyncSession = false,
                    HasMessageToDatabaseMappingConvention = context.Settings.HasSetting(MessageToDatabaseMappingConvention),
                });
            }
        }