FruityFoundation/FruityFoundation.DataAccess.Core/DbConnectionFactory.cs

28 lines
809 B
C#
Raw Normal View History

2024-06-23 22:27:05 -04:00
using System.Data.Common;
using FruityFoundation.DataAccess.Abstractions;
2024-07-05 20:03:12 -04:00
using Microsoft.Extensions.DependencyInjection;
2024-06-23 22:27:05 -04:00
namespace FruityFoundation.DataAccess.Core;
public class DbConnectionFactory : IDbConnectionFactory
{
2024-07-05 20:03:12 -04:00
private readonly IServiceProvider _serviceProvider;
2024-06-23 22:27:05 -04:00
2024-07-05 20:03:12 -04:00
public DbConnectionFactory(IServiceProvider serviceProvider)
2024-06-23 22:27:05 -04:00
{
2024-07-05 20:03:12 -04:00
_serviceProvider = serviceProvider;
2024-06-23 22:27:05 -04:00
}
public INonTransactionalDbConnection<ReadWrite> CreateConnection()
{
2024-07-05 20:03:12 -04:00
var nonTxConnection = _serviceProvider.GetRequiredService<INonTransactionalDbConnection<ReadWrite>>();
2024-06-23 22:27:05 -04:00
return nonTxConnection;
}
public INonTransactionalDbConnection<ReadOnly> CreateReadOnlyConnection()
{
2024-07-05 20:03:12 -04:00
var nonTxConnection = _serviceProvider.GetRequiredService<INonTransactionalDbConnection<ReadOnly>>();
2024-06-23 22:27:05 -04:00
return nonTxConnection;
}
}