-
Notifications
You must be signed in to change notification settings - Fork 8
In Memory Data Source Provider
João Romeiro edited this page Apr 23, 2023
·
1 revision
With a in-memory data source provider, you can define rules and manage them in-memory, and you can also manage their lifetime in memory.
There are 2 configuration possibilities:
-
Setting the in-memory data source attached to rules engine lifetime.
RulesEngine<ContentTypes, ConditionTypes> rulesEngine = RulesEngineBuilder.CreateRulesEngine() .WithContentType<ContentTypes>() .WithConditionType<ConditionTypes>() .SetInMemoryDataSource() .Build();
-
Registering in-memory data source on dependency injection and using service provider.
// Registering in-memory data source on dependency injection. (...) services.AddInMemoryRulesDataSource<ContentTypes, ConditionTypes>(ServiceLifetime.Singleton); (...) // Creating the rules engine specifying as parameter the service provider. RulesEngine<ContentTypes, ConditionTypes> rulesEngine = RulesEngineBuilder.CreateRulesEngine() .WithContentType<ContentTypes>() .WithConditionType<ConditionTypes>() .SetInMemoryDataSource(serviceProvider) .Build();
Keep in mind that a in-memory data source is volatile, and will need you to build a rules engine and add rules everytime you start your application.