<p>In our project we are using .net 5.0 with CQRS with postgre.
Our all apps are containerized and runs on kubernetes. For postgre we have master -&gt; slave configuration with pgpool ( for writes), for reads it is directly getting from slaves but pgpool configured before master node.</p>
<p>Is it possible to configure for CQRS (MediatR) using one connection for read and another connection for write?</p>
<p>My DI configuration looks like:</p>
<pre><code>        services.AddDbContext&lt;DataContext&gt;(opt =&gt;
        {
            opt.EnableDetailedErrors();
            opt.UseLazyLoadingProxies();
            opt.UseNpgsql(configuration.GetConnectionString(&quot;TaikunConnection&quot;),
                options =&gt;
                {
                    options.MigrationsAssembly(typeof(DataContext).Assembly.FullName);
                    options.EnableRetryOnFailure();
                    options.CommandTimeout((int)TimeSpan.FromMinutes(10).TotalSeconds);
                });
        });

        services.AddScoped&lt;IDataContext&gt;(provider =&gt; provider.GetService&lt;DataContext&gt;());

        var builder = services.AddIdentityCore&lt;User&gt;()
            .AddEntityFrameworkStores&lt;DataContext&gt;();

        var identityBuilder = new IdentityBuilder(builder.UserType, builder.Services);
        identityBuilder.AddSignInManager&lt;SignInManager&lt;User&gt;&gt;();
        identityBuilder.AddUserManager&lt;UserManager&lt;User&gt;&gt;();
</code></pre>

Arzu Suleymanov
<p>You can use 2 different DB contexts:</p>
<pre><code>services.AddDbContext&lt;DataWriteContext&gt;(opt =&gt;
        {
            opt.EnableDetailedErrors();
            opt.UseLazyLoadingProxies();
            opt.UseNpgsql(configuration.GetConnectionString(&quot;TaikunConnectionForWrite&quot;),
                options =&gt;
                {
                    options.MigrationsAssembly(typeof(DataContext).Assembly.FullName);
                    options.EnableRetryOnFailure();
                    options.CommandTimeout((int)TimeSpan.FromMinutes(10).TotalSeconds);
                });
        });

services.AddDbContext&lt;DataReadContext&gt;(opt =&gt;
        {
            opt.EnableDetailedErrors();
            opt.UseLazyLoadingProxies();
            opt.UseNpgsql(configuration.GetConnectionString(&quot;TaikunConnectionForRead&quot;),
                options =&gt;
                {
                    options.MigrationsAssembly(typeof(DataContext).Assembly.FullName);
                    options.EnableRetryOnFailure();
                    options.CommandTimeout((int)TimeSpan.FromMinutes(10).TotalSeconds);
                });
        });
</code></pre>
