- EF配置
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace SimplCommerce.Module.Core.Extensions
{
/// <summary>
/// EF配置
/// </summary>
public class EFConfigSource : IConfigurationSource//Microsoft.Extensions.Configuration
{
private readonly Action<DbContextOptionsBuilder> _optionsAction;
public EFConfigSource(Action<DbContextOptionsBuilder> optionsAction)
{
_optionsAction = optionsAction;
}
public IConfigurationProvider Build(IConfigurationBuilder builder)
{
return new EFConfigProvider(_optionsAction);
}
}
}
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace SimplCommerce.Module.Core.Extensions
{
public static class EFConfigurationProviderExtension
{
public static IConfigurationBuilder AddEntityFrameworkConfig(this IConfigurationBuilder builder, Action<DbContextOptionsBuilder> setup)
{
return builder.Add(new EFConfigSource(setup));
}
}
}
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
namespace SimplCommerce.Infrastructure.Modules
{
/// <summary>
/// 模块配置管理器
/// 从 modules.json 文件中读取模块-->实体嘞ModuleInfo
/// </summary>
public class ModuleConfigurationManager : IModuleConfigurationManager
{
public static readonly string ModulesFilename = "modules.json";
/// <summary>
/// 从 modules.json 文件中读取模块-->实体嘞ModuleInfo
/// </summary>
/// <returns></returns>
public IEnumerable<ModuleInfo> GetModules()
{
var modulesPath = Path.Combine(GlobalConfiguration.ContentRootPath, ModulesFilename);
using var reader = new StreamReader(modulesPath);
string content = reader.ReadToEnd();
dynamic modulesData = JsonConvert.DeserializeObject(content);
foreach (dynamic module in modulesData)
{
yield return new ModuleInfo
{
Id = module.id,
Version = Version.Parse(module.version.ToString()),
IsBundledWithHost = module.isBundledWithHost
};
}
}
}
}
标签:optionsAction,Microsoft,核心,System,SimplCommerce,using,public
From: https://www.cnblogs.com/walterwhite/p/17058323.html