Example #1
0
    protected override void Setup(FeatureConfigurationContext context)
    {
        var settings = context.Settings;

        settings.EnableFeature <StorageType.Sagas>();

        var sqlVariant = settings.GetSqlVariant();

#pragma warning disable 618
        var commandBuilder = new SagaCommandBuilder(sqlVariant);
#pragma warning restore 618
        var jsonSerializerSettings = SagaSettings.GetJsonSerializerSettings(settings);
        var jsonSerializer         = BuildJsonSerializer(jsonSerializerSettings);
        var readerCreator          = SagaSettings.GetReaderCreator(settings);
        if (readerCreator == null)
        {
            readerCreator = reader => new JsonTextReader(reader);
        }
        var writerCreator = SagaSettings.GetWriterCreator(settings);
        if (writerCreator == null)
        {
            writerCreator = writer => new JsonTextWriter(writer);
        }
        var nameFilter = SagaSettings.GetNameFilter(settings);
        if (nameFilter == null)
        {
            nameFilter = (sagaName => sagaName);
        }
        var versionDeserializeBuilder = SagaSettings.GetVersionSettings(settings);
        var tablePrefix = settings.GetTablePrefix();
        var schema      = settings.GetSchema();
        var infoCache   = new SagaInfoCache(
            versionSpecificSettings: versionDeserializeBuilder,
            jsonSerializer: jsonSerializer,
            readerCreator: readerCreator,
            writerCreator: writerCreator,
            commandBuilder: commandBuilder,
            tablePrefix: tablePrefix,
            schema: schema,
            sqlVariant: sqlVariant,
            metadataCollection: settings.Get <SagaMetadataCollection>(),
            nameFilter: nameFilter);
        var sagaPersister = new SagaPersister(infoCache, sqlVariant);
        var container     = context.Container;
        container.ConfigureComponent(() => infoCache, DependencyLifecycle.SingleInstance);
        container.ConfigureComponent <ISagaPersister>(() => sagaPersister, DependencyLifecycle.SingleInstance);
    }
    protected override void Setup(FeatureConfigurationContext context)
    {
        var settings = context.Settings;

        var customJsonSettings          = SagaSettings.GetJsonSerializerSettings(settings);
        var versionSpecificJsonSettings = SagaSettings.GetVersionSettings(settings);
        var customSagaWriter            = SagaSettings.GetWriterCreator(settings);
        var customSagaReader            = SagaSettings.GetReaderCreator(settings);

        settings.AddStartupDiagnosticsSection("NServiceBus.Persistence.Sql.Sagas", new
        {
            CustomJsonSettings          = customJsonSettings != null,
            VersionSpecificJsonSettings = versionSpecificJsonSettings != null,
            CustomSagaWriter            = customSagaWriter != null,
            CustomSagaReader            = customSagaReader != null
        });
    }
    static SagaInfoCache BuildSagaInfoCache(SqlDialect sqlDialect, ReadOnlySettings settings)
    {
        var jsonSerializerSettings = SagaSettings.GetJsonSerializerSettings(settings);
        var jsonSerializer         = BuildJsonSerializer(jsonSerializerSettings);

        sqlDialect.ValidateJsonSettings(jsonSerializer);
        var readerCreator = SagaSettings.GetReaderCreator(settings);

        if (readerCreator == null)
        {
            readerCreator = reader => new JsonTextReader(reader);
        }
        var writerCreator = SagaSettings.GetWriterCreator(settings);

        if (writerCreator == null)
        {
            writerCreator = writer => new JsonTextWriter(writer);
        }
        var nameFilter = SagaSettings.GetNameFilter(settings);

        if (nameFilter == null)
        {
            nameFilter = sagaName => sagaName;
        }
        var versionDeserializeBuilder = SagaSettings.GetVersionSettings(settings);
        var tablePrefix = settings.GetTablePrefix();

        return(new SagaInfoCache(
                   versionSpecificSettings: versionDeserializeBuilder,
                   jsonSerializer: jsonSerializer,
                   readerCreator: readerCreator,
                   writerCreator: writerCreator,
                   tablePrefix: tablePrefix,
                   sqlDialect: sqlDialect,
                   metadataCollection: settings.Get <SagaMetadataCollection>(),
                   nameFilter: nameFilter));
    }