Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Last active June 30, 2021 07:19
Show Gist options
  • Save gistlyn/d4f31771aa8e93c3108909b48e96debb to your computer and use it in GitHub Desktop.
Save gistlyn/d4f31771aa8e93c3108909b48e96debb to your computer and use it in GitHub Desktop.
mixtemplates
public class AppHost : AppHostBase
{
public AppHost() : base("Web",typeof(MyServices).Assembly){}
// Configure your AppHost with the necessary configuration
// and dependencies your App needs
public override void Configure(Container container)
{
SetConfig(new HostConfig {
DebugMode = AppSettings.Get(
nameof(HostConfig.DebugMode), false)
});
}
}
public class ConfigureDb : IConfigureServices,IConfigureAppHost
{
IConfiguration config { get; }
public ConfigureDb(IConfiguration configuration) =>
config = configuration;
public void Configure(IServiceCollection services)
{
services.AddSingleton<IDbConnectionFactory>(
new OrmLiteConnectionFactory(
config.GetConnectionString("DefaultConnection")
?? ":memory:",
SqliteDialect.Provider));
}
public void Configure(IAppHost appHost)
{
appHost.GetPlugin<SharpPagesFeature>()?
.ScriptMethods.Add(new DbScriptsAsync());
// Create non-existing Table and add Seed Data Example
// using var db = appHost
// .Resolve<IDbConnectionFactory>().Open();
// if (db.CreateTableIfNotExists<MyTable>()) {
// db.Insert(new MyTable { Name = "Seed Data" });
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment