Class EfCoreDataStore<T, TMarker>
- Namespace
- Savvyio.Extensions.DependencyInjection.EFCore
- Assembly
- Savvyio.Extensions.DependencyInjection.EFCore.dll
Provides a default implementation of the IPersistentDataStore<T, TOptions, TMarker> interface to support multiple implementations that serves as an abstraction layer before the actual I/O communication with a source of data using Microsoft Entity Framework Core.
public class EfCoreDataStore<T, TMarker> : EfCoreDataStore<T>, IPersistentDataStore<T, EfCoreQueryOptions<T>, TMarker>, IPersistentDataStore<T, EfCoreQueryOptions<T>>, IWritableDataStore<T, TMarker>, IWritableDataStore<T>, IReadableDataStore<T, TMarker>, IReadableDataStore<T>, ISearchableDataStore<T, EfCoreQueryOptions<T>, TMarker>, ISearchableDataStore<T, EfCoreQueryOptions<T>>, IDeletableDataStore<T, TMarker>, IDataStore<T, TMarker>, IDependencyInjectionMarker<TMarker>, IDeletableDataStore<T>, IDataStore<T> where T : class
Type Parameters
TThe type of the DTO.
TMarkerThe type used to mark the implementation that this data access object represents. Optimized for Microsoft Dependency Injection.
- Inheritance
-
EfCoreDataStore<T, TMarker>
- Implements
-
IPersistentDataStore<T, EfCoreQueryOptions<T>, TMarker>IWritableDataStore<T, TMarker>IReadableDataStore<T, TMarker>ISearchableDataStore<T, EfCoreQueryOptions<T>, TMarker>IDeletableDataStore<T, TMarker>IDataStore<T, TMarker>IDependencyInjectionMarker<TMarker>IDataStore<T>
- Inherited Members
Examples
The DI-registered EfCoreDataStore<T, TContext> resolves as IPersistentDataStore<T, EfCoreQueryOptions<T>> when registered via AddEfCoreDataStore. The data source registered by AddEfCoreDataSource provides the context; the concrete store type adds entity-specific query logic. The example resolves the store from the provider and confirms the registered concrete type.
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Savvyio;
using Savvyio.Data;
using Savvyio.Extensions.DependencyInjection.Data;
using Savvyio.Extensions.DependencyInjection.EFCore;
using Savvyio.Extensions.EFCore;
namespace ExampleApp;
public sealed class MarkerBasedDataStoreExample
{
public bool IsResolvedAsMarkedStore()
{
var services = new ServiceCollection();
services.AddEfCoreDataSource<CatalogMarker>(options =>
{
options.ContextConfigurator = builder => builder.EnableDetailedErrors();
options.ModelConstructor = modelBuilder => modelBuilder.Entity<Product>().HasKey(product => product.Id);
});
services.AddEfCoreDataStore<Product, CatalogMarker>();
using var provider = services.BuildServiceProvider();
var store = provider.GetRequiredService<IPersistentDataStore<Product, EfCoreQueryOptions<Product>, CatalogMarker>>();
return store is EfCoreDataStore<Product, CatalogMarker>;
}
}
public sealed class CatalogMarker
{
}
public sealed class Product : IIdentity<Guid>
{
public Product(Guid id, string name)
{
Id = id;
Name = name;
}
public Guid Id { get; }
public string Name { get; private set; } = string.Empty;
}
Constructors
EfCoreDataStore(IEfCoreDataSource<TMarker>)
Initializes a new instance of the EfCoreDataStore<T, TMarker> class.
public EfCoreDataStore(IEfCoreDataSource<TMarker> source)
Parameters
sourceIEfCoreDataSource<TMarker>The IEfCoreDataSource<TMarker> that handles actual I/O communication with a source of data.