61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace iPackage.Core.Web.Extensions
|
|
{
|
|
public class DbContextOptionCustomExtensionsInfo : DbContextOptionsExtensionInfo
|
|
{
|
|
public DbContextOptionCustomExtensionsInfo(IDbContextOptionsExtension extension) : base(extension)
|
|
{
|
|
}
|
|
|
|
public override long GetServiceProviderHashCode()
|
|
{
|
|
return Extension.GetHashCode();
|
|
}
|
|
|
|
public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
|
|
{
|
|
}
|
|
|
|
public override bool IsDatabaseProvider { get; }
|
|
public override string LogFragment { get; }
|
|
}
|
|
public class DbContextOptionCustomExtensions : IDbContextOptionsExtension
|
|
{
|
|
public void ApplyServices(IServiceCollection services)
|
|
{
|
|
|
|
}
|
|
|
|
public void Validate(IDbContextOptions options)
|
|
{
|
|
|
|
}
|
|
|
|
public DbContextOptionCustomExtensions()
|
|
{
|
|
Info = new DbContextOptionCustomExtensionsInfo(this);
|
|
}
|
|
public Assembly ProjectAssembly { get; set; }
|
|
public DbContextOptionsExtensionInfo Info { get; }
|
|
}
|
|
public static class ApplicationContextExtensions
|
|
{
|
|
public static DbContextOptionsBuilder UseProjectAssembly(this DbContextOptionsBuilder contextOptions, Assembly projectAssembly)
|
|
{
|
|
var extension = new DbContextOptionCustomExtensions
|
|
{
|
|
ProjectAssembly = projectAssembly
|
|
};
|
|
((IDbContextOptionsBuilderInfrastructure)contextOptions).AddOrUpdateExtension(extension);
|
|
return contextOptions;
|
|
}
|
|
}
|
|
}
|