This repository has been archived by the owner on Apr 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 318
Quickstart Local
waleswood edited this page Jun 27, 2016
·
3 revisions
- 打开Nuget程序包控制台或在资源管理器右键“管理Nuget程序包”,引用程序包
- 向工程添加 OSharp.App.Local
- 在App.Config文件中添加
name="default"
的数据库连接串
<connectionStrings>
<add name="default" connectionString="Data Source=.; Integrated Security=True; Initial Catalog=OSharp.Default; Pooling=True; MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
- 添加EntityInfo与Function实体类的实体映射配置
public class EntityInfoConfiguration : EntityConfigurationBase<EntityInfo, Guid>
{ }
public class FunctionConfiguration : EntityConfigurationBase<Function, Guid>
{ }
- 在主程序的主方法中添加初始化代码,以控制台程序为例
internal class Program : ISingletonDependency
{
private static Program _program;
public IIocResolver IocResolver { get; set; }
public IIdentityContract IdentityContract { get; set; }
private static void Main(string[] args)
{
try
{
Console.WriteLine("正在初始化,请稍候……");
Stopwatch watch = Stopwatch.StartNew();
IServicesBuilder builder = new ServicesBuilder(new ServiceBuildOptions());
IServiceCollection services = builder.Build();
services.AddLog4NetServices();
services.AddDataServices();
services.AddAutoMapperServices();
IIocBuilder iocBuilder = new LocalAutofacIocBuilder(services);
IFrameworkInitializer initializer = new FrameworkInitializer();
initializer.Initialize(iocBuilder);
_program = iocBuilder.ServiceProvider.GetService<Program>();
watch.Stop();
Console.WriteLine("程序初始化完毕并启动成功,耗时:{0}", watch.Elapsed);
}
catch (ReflectionTypeLoadException e)
{
Console.WriteLine(e);
Console.WriteLine("LoaderExceptions:");
Exception[] exs = e.LoaderExceptions;
foreach (Exception ex in exs)
{
Console.WriteLine(ex);
}
return;
}
catch (Exception e)
{
Console.WriteLine(e);
Console.ReadLine();
return;
}
}
}
- 运行项目,即可完成初始化,将会自动生成相应的数据库,并初始化好需要的数据
power by @osharp-team (osharp.org)