1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using Application.ATG_Classic_App;
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Application.ATG_Classic_App
- {
- public interface IDbContextFactory : IDisposable
- {
- void AddProvider(IDbContextProvider provider);
- T CreateDbContext<T>() where T : DbContext;
- }
- public interface IDbContextProvider : IDisposable
- {
- T CreateDbContext<T>() where T : DbContext;
- }
- public class DefaultDbContextFactory : IDbContextFactory
- {
- private IDbContextProvider provider;
- public void AddProvider(IDbContextProvider provider)
- {
- this.provider = provider;
- }
- public T CreateDbContext<T>() where T : DbContext
- {
- return this.provider.CreateDbContext<T>();
- }
- public void Dispose()
- {
- //throw new NotImplementedException();
- }
- }
- public class ClassicAtgDbContextProvider : IDbContextProvider
- {
- /// <summary>
- ///
- /// </summary>
- /// <param name="options">leave null to create Sqlite database</param>
- /// <returns></returns>
- public T CreateDbContext<T>() where T : DbContext
- {
- var options = new DbContextOptionsBuilder<AppDbContext>()
- .UseSqlite("Data Source=Application.ATG_Classic_App_database.db")
- .Options;
- return new AppDbContext(options) as T;
- }
- public void Dispose()
- {
- //throw new NotImplementedException();
- }
- }
- }
|