Ejemplo n.º 1
0
        public static IConveyBuilder AddMessageInbox(this IConveyBuilder builder, string sectionName = SectionName)
        {
            if (!builder.TryRegister(RegistryName))
            {
                return(builder);
            }

            var options = builder.GetOptions <InboxOptions>(sectionName);

            builder.Services.AddSingleton(options);
            if (!options.Enabled)
            {
                builder.RegisterInMemoryInbox();
                return(builder);
            }

            switch (options.Type?.ToLowerInvariant() ?? string.Empty)
            {
            case "memory":
                builder.RegisterInMemoryInbox();
                break;

            case "mongo":
                builder.AddMongo();
                builder.Services.AddTransient <IMessageInbox, MongoMessageInbox>();
                builder.Services.AddTransient <MongoInboxInitializer>();
                builder.AddInitializer <MongoInboxInitializer>();
                break;

            case "redis":
                builder.Services.AddTransient <IMessageInbox, RedisMessageInbox>();
                break;

            default:
                builder.RegisterInMemoryInbox();
                break;
            }

            return(builder);
        }