Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Last active February 7, 2024 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gistlyn/3abcb76db6be3bd56a3505cd6effb8a7 to your computer and use it in GitHub Desktop.
Save gistlyn/3abcb76db6be3bd56a3505cd6effb8a7 to your computer and use it in GitHub Desktop.
Configure dynamic RDBMS validations source
using ServiceStack;
using ServiceStack.Data;
using ServiceStack.Caching;
[assembly: HostingStartup(typeof(MyApp.ConfigureValidation))]
namespace MyApp;
public class ConfigureValidation : IHostingStartup
{
// Add support for dynamically generated db rules
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices(services => {
services.AddSingleton<IValidationSource>(c =>
new OrmLiteValidationSource(
c.GetRequiredService<IDbConnectionFactory>(),
c.GetRequiredService<MemoryCacheClient>()));
})
.ConfigureAppHost(appHost =>
appHost.Resolve<IValidationSource>().InitSchema());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment