You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Framework/Connected.Data/Storage/StorageProvider.cs

37 lines
1.3 KiB

using Connected.Data.DataProtection;
using Connected.Entities;
using Connected.Entities.Storage;
using Connected.Middleware;
using Connected.ServiceModel.Transactions;
namespace Connected.Data.Storage;
internal sealed class StorageProvider : IStorageProvider
{
public StorageProvider(IEntityProtectionService dataProtection, IConnectionProvider connections, ITransactionContext transactions, IMiddlewareService middleware)
{
DataProtection = dataProtection;
Connections = connections;
Transactions = transactions;
Middleware = middleware;
}
private IEntityProtectionService DataProtection { get; }
private IConnectionProvider Connections { get; }
private ITransactionContext Transactions { get; }
private IMiddlewareService Middleware { get; }
/// <summary>
/// Opens <see cref="IDatabaseContext{TEntity}"/> for reading and writing entities.
/// </summary>
/// <typeparam name="TEntity">Type type of the entity to be used.</typeparam>
/// <returns>The <see cref="IDatabaseContext{TEntity}"/> on which LINQ queries and updates can be performed.</returns>
public IStorage<TEntity> Open<TEntity>()
where TEntity : IEntity
{
var result = new EntityStorage<TEntity>(DataProtection, Middleware, Connections, Transactions);
AsyncUtils.RunSync(result.Initialize);
return result;
}
}