-
Notifications
You must be signed in to change notification settings - Fork 5
Config File Setup
Johelvis Guzman edited this page Apr 2, 2019
·
18 revisions
If you wish to use the configuration files to configure the repositories, please follow these steps:
Element | Description |
---|---|
defaultContextFactory | Defines the default repository context factory to use |
interceptors | Accepts a collection of interceptor elements |
Each element can accept a collection of parameters which can be used to construct the type, or a key value collection as well
Element | Description |
---|---|
parameters | Accepts a collection of parameter elements |
App.config In order for the repositories to read data from the App.config the user will need to add a custom section handler and a configuration section:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- Configuration section-handler declaration area. -->
<configSections>
<section name="repository" type="DotNetToolkit.Repository.Internal.ConfigFile.ConfigurationSection, DotNetToolkit.Repository" />
<!-- Other <section> and <sectionGroup> elements. -->
</configSections>
<!-- Configuration section settings area. -->
<repository>
<defaultContextFactory type="DotNetToolkit.Repository.InMemory.Internal.InMemoryRepositoryContextFactory, DotNetToolkit.Repository.InMemory" />
<interceptors>
<interceptor type="ExampleApplication.TestRepositoryInterceptor, ExampleApplication">
<parameters>
<parameter value="random parameter"/>
</parameters>
</interceptor>
</interceptors>
</repository>
</configuration>
var options = new RepositoryOptionsBuilder()
.UseConfiguration() // it will use the App.config file
.Options;
appsettings.config In order for the repositories to read data from the appsettings.json file the user will need to add a section to the file:
{
"repository": {
"defaultContextFactory": {
"type": "DotNetToolkit.Repository.InMemory.Internal.InMemoryRepositoryContextFactory, DotNetToolkit.Repository.InMemory"
},
"interceptors": [
{
"interceptor": {
"type": "DotNetToolkit.Repository.Integration.Test.Data.TestRepositoryInterceptor, DotNetToolkit.Repository.Integration.Test",
"parameters": [
{
"parameter": {
"type": "System.String",
"value": "random param"
}
},
{
"parameter": {
"type": "System.Boolean",
"value": "True"
}
}
]
}
}
]
}
}
var options = new RepositoryOptionsBuilder()
.UseConfiguration(Microsoft.Extensions.Configuration.IConfiguration) // it will use a configuration section
.Options;
Additionally, any element type that is defined in the configuration file can be resolved by using the ConfigurationProvider.SetDefaultFactory.