Skip to content

Instantly share code, notes, and snippets.

@gistlyn gistlyn/Configure.Db.cs

Last active Jun 22, 2019
What would you like to do?
Configure AppHost to use OrmLite with Orcale
dotnet add package ServiceStack.OrmLite.Oracle
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ServiceStack;
using ServiceStack.Data;
using ServiceStack.DataAnnotations;
using ServiceStack.OrmLite;
namespace MyApp
public class MyTable
public int Id { get; set; }
public string Name { get; set; }
public class ConfigureDb : IConfigureServices, IConfigureAppHost
IConfiguration Configuration { get; }
public ConfigureDb(IConfiguration configuration) => Configuration = configuration;
public void Configure(IServiceCollection services)
services.AddSingleton<IDbConnectionFactory>(new OrmLiteConnectionFactory(
?? "Data Source=localhost:48401/XE;User ID=system;Password=test",
public void Configure(IAppHost appHost)
appHost.GetPlugin<SharpPagesFeature>()?.ScriptMethods.Add(new DbScriptsAsync());
using (var db = appHost.Resolve<IDbConnectionFactory>().Open())
if (db.CreateTableIfNotExists<MyTable>())
db.Insert(new MyTable { Name = "Seed Data for new MyTable" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.