-
Notifications
You must be signed in to change notification settings - Fork 0
v. Data Provider
Data provider needs to setup with required dependencies. Provide implementations of below dependencies to construct the data provider.
-
ILogger<DataProvider<TEntity>>
- logger implementation. default no logger. -
IEntitySchema<TEntity>
- mandatory entity schema definition for entity's object graph. -
IQueryEngine
- implementation of query engine to execute queries (of type IQuery) with supported data storage. -
ISchemaPathMatcher
- implementation of schema path matcher to use custom schema paths with entity schema definition.
Example constructors:
i. With EntitySchema
and QueryEngine
implementations.
public DataProvider(IEntitySchema<TEntity> entitySchema, params IQueryEngine[] queryEngines)
ii. With Logger
, EntitySchema
, QueryEngine
, and SchemaPathmMatcher
for custom schema paths mapping in entity schema definition.
public DataProvider(ILogger<DataProvider<TEntity>> logger, IEntitySchema<TEntity> entitySchema, ISchemaPathMatcher schemaPathMatcher, params IQueryEngine[] queryEngines)
Construct DataProvider using Schemio.SQL.QueryEngine
query engine.
var provider = new DataProvider(new CustomerSchema(), new Schemio.SQL.QueryEngine(new SQLConfiguration()));
Construct DataProvider using Schemio.EntityFramework.QueryEngine
query engine.
var provider = new DataProvider(new CustomerSchema(), Schemio.EntityFramework.QueryEngine());
With ServiceCollection, you should call the services.UseSchemio()
method for IoC registration.
To configure Data provider with SQL Query engine, use fluent registration apis as shown below -
services.UseSchemio<Customer>(With.Schema<Customer>(c => new CustomerSchema())
.AddEngine(c => new QueryEngine(new SQLConfiguration { ConnectionSettings = new ConnectionSettings {
Providername = "System.Data.SqlClient",
ConnectionString ="Data Source=Powerstation; Initial Catalog=Customer; Integrated Security=SSPI;"
}}))
.LogWith(c => new Logger<IDataProvider<Customer>>(c.GetService<ILoggerFactory>())));
To configure Data provider with Entity Framework Query engine, use fluent registration apis shown as below -
services.AddDbContextFactory<CustomerDbContext>(options => options.UseSqlServer(YourSqlConnection), ServiceLifetime.Scoped);
services.AddLogging();
services.UseSchemio<Customer>(With.Schema<Customer>(c => new CustomerSchema())
.AddEngine(c => new QueryEngine<CustomerDbContext>(c.GetService<IDbContextFactory<CustomerDbContext>>()))
.LogWith(c => new Logger<IDataProvider<Customer>>(c.GetService<ILoggerFactory>())));
Please Note:
You can combine multiple query engines and implement different types of queries to execute on different supported platforms.
To use Data provider, Inject IDataProvider using constructor & property injection method or explicity Resolve using service provider ie. IServiceProvider.GetService(typeof(IDataProvider<>))