PiBox.Plugins.Persistence.InMemory is a plugin that allows other PiBox components to use the persistance repository abstractions with an in memory implementation for the repositories.
public class PluginReadme : IPluginEndpointsConfiguration, IPluginServiceConfiguration, IPluginApplicationConfiguration, IPluginControllerConfiguration, IPluginHealthChecksConfiguration
{ private readonly PluginReadmeTemplateConfig _pluginReadmeTemplateConfig;publicPluginReadme(PluginReadmeTemplateConfig pluginReadmeTemplateConfig) { _pluginReadmeTemplateConfig = pluginReadmeTemplateConfig; } public voidConfigureServices(IServiceCollection serviceCollection) { // the plugins does the following registrationsserviceCollection.AddSingleton(typeof(InMemoryStore));serviceCollection.AddSingleton(typeof(IRepository<>),typeof(InMemoryRepository<>));serviceCollection.AddSingleton(typeof(IReadRepository<>),typeof(InMemoryRepository<>)); // if you have other persistence plugins installted you'll // need to register the explitict types which should be used/registered with this plugin // otherwise the plugin load order will determine which persistence plugin will be used as a default for all // types from PiBox.Plugins.Persistence.Abstractions }}
Usage
You can use all of the registered types from the lib PiBox.Plugins.Persistence.Abstractions
publicinterfaceIExampleService{voidDoStuff();}publicclassExampleService:IExampleService{privatereadonlyPluginReadmeTemplateConfig _pluginReadmeTemplateConfig;privatereadonlyIReadRepository<MyPoco> _readRepository; public ExampleService(PluginReadmeTemplateConfig pluginReadmeTemplateConfig, IReadRepository<MyPoco> readRepository)
{ _pluginReadmeTemplateConfig = pluginReadmeTemplateConfig; _readRepository = readRepository; }publicasyncTaskDoStuff() { // for examplevar result =await_readRepository.FindByIdAsync(); }}