FruityFoundation/FruityFoundation.DataAccess.Core/DbConnectionFactory.cs
2024-07-05 20:03:12 -04:00

28 lines
809 B
C#

using System.Data.Common;
using FruityFoundation.DataAccess.Abstractions;
using Microsoft.Extensions.DependencyInjection;
namespace FruityFoundation.DataAccess.Core;
public class DbConnectionFactory : IDbConnectionFactory
{
private readonly IServiceProvider _serviceProvider;
public DbConnectionFactory(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public INonTransactionalDbConnection<ReadWrite> CreateConnection()
{
var nonTxConnection = _serviceProvider.GetRequiredService<INonTransactionalDbConnection<ReadWrite>>();
return nonTxConnection;
}
public INonTransactionalDbConnection<ReadOnly> CreateReadOnlyConnection()
{
var nonTxConnection = _serviceProvider.GetRequiredService<INonTransactionalDbConnection<ReadOnly>>();
return nonTxConnection;
}
}