You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.8 KiB

using System;
using System.IO;
using System.Windows;
using Autofac;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Configuration;
using log4net.Config;
using SqlSugar;
using SqlSugar.IOC;
7 months ago
namespace WpfStarter;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
7 months ago
public App()
{
XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\log4net.config"));
7 months ago
var cb = new ContainerBuilder();
cb.Register(c =>
{
7 months ago
var db = new SqlSugarClient(new ConnectionConfig
{
7 months ago
ConfigId = AppSettingsConstVars.ConfigId,
ConnectionString = AppSettingsConstVars.DbSqlConnection, // 设置数据库连接字符串
DbType = AppSettingsConstVars.DbDbType == IocDbType.MySql.ToString()
? DbType.MySql
: DbType.SqlServer,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attribute
});
return db;
}).As<ISqlSugarClient>().InstancePerLifetimeScope();
7 months ago
cb.RegisterModule(new AutofacModuleRegister());
7 months ago
var baseType = typeof(Window);
cb.RegisterAssemblyTypes(typeof(App).Assembly)
.Where(t => baseType.IsAssignableFrom(t) && t != baseType)
.InstancePerDependency();
7 months ago
// cb.RegisterType(typeof(MainWindow)).SingleInstance();
7 months ago
// 构建容器
var Container = cb.Build();
AppInfo.Container = Container.BeginLifetimeScope("root");
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var mainWindow = AppInfo.Container.Resolve<MainWindow>();
mainWindow.Show();
}
}