An collection of IQueryable based DataSource libraries for the ServiceStack AutoQuery feature
This project makes it possible to expose data with the ServiceStack AutoQuery from providers that leverage the IQueryable interface.
There are several data providers that implement the IQueryable interface for querying. The most popular is Microsoft's Entity Framework. However, ServiceStack's SQL provider can already handle querying from many of the data providers that Entity Framework targets. So this library will initially focus on Document Database providers (i.e. No-SQL).
Data providers will include:
- Microsoft Entity Framework
- Microsoft Azure CosmosDB
- MongoDB
- RavenDB
- NOTE: DocumentQuery doesn't implement IQueryable, but Query does translate into a DocumentQuery.
The secret sauce in making this work is the use of the System.Linq.Dynamic.Core library which dynamically transforms string based queries to LINQ expressions. This allows the library to construct the query with less regard to the strong-typed nature of C#.
Install from NuGet:
Install-Package ServiceStack.Azure.CosmosDB
Simply add the AutoQueryDataFeature
in your AppHost.Configure()
method:
public override void Configure(Container container)
{
// Get Data Provider Settings from Configuration
var endpointUrl = AppSettings.Get<string>("CosmosDb.EndPointUrl");
var authorizationKey = AppSettings.Get<string>("CosmosDb.AuthorizationKey");
var databaseId = AppSettings.Get<string>("CosmosDb.DatabaseId");
var collectionId = AppSettings.Get<string>("CosmosDb.CollectionId");
// Create a Document Client
var docClient = new DocumentClient(
new Uri(endpointUrl),
authorizationKey);
// Register the Document Client into the IOC
container.Register<IDocumentClient>(c => docClient);
var requestOptions = new RequestOptions { ConsistencyLevel = ConsistencyLevel.Session };
// Add AuthQueryDataFeature plugin with a DataSource
// you will need to add a data source for each TDocument type
Plugins.Add(new AutoQueryDataFeatureFeature()
.AddDataSource(ctx => ctx.CosmosDBDataSource<TDocument>(docClient, databaseId, collectionId, requestOptions)));
}
Install from NuGet:
Install-Package ServiceStack.MongoDB
Simply add the AutoQueryDataFeature
in your AppHost.Configure()
method:
public override void Configure(Container container)
{
// Get Data Provider Settings from Configuration
var connectionString = AppSettings.Get<string>("MongoDB.ConnectionString");
var databaseId = AppSettings.Get<string>("MongoDB.DatabaseId");
var collectionId = AppSettings.Get<string>("MongoDB.CollectionId");
// Create a Mongo Client
var mongoClient = new MongoClient(
new MongoUrl(connectionString));
// Register the Document Client into the IOC
container.Register<IMongoClient>(c => mongoClient);
// Add AuthQueryDataFeature plugin with a DataSource
Plugins.Add(new AutoQueryDataFeatureFeature()
.AddDataSource(ctx => ctx.MongoDBDataSource<TDocument>(mongoClient, databaseId, collectionId)));
}
More documentation about how the AutoQueryFeature
works, how to target non-SQL data sources, and how to customize it are available in here
Want to get involved in this project? or want to help improve this capability for your services? just send us a message or pull-request!