forked from NewLifeX/X
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXCodeService.cs
More file actions
44 lines (39 loc) · 1.49 KB
/
XCodeService.cs
File metadata and controls
44 lines (39 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using NewLife.Model;
using XCode.DataAccessLayer;
namespace XCode.Model
{
/// <summary>XCode服务对象提供者</summary>
class XCodeService
{
#region 当前静态服务容器
/// <summary>当前对象容器</summary>
public static IObjectContainer Container { get { return ObjectContainer.Current; } }
#endregion
static XCodeService()
{
var container = Container;
container.Register<IDataTable, XTable>()
.AutoRegister<IDataRowEntityAccessorProvider, DataRowEntityAccessorProvider>()
.AutoRegister<IEntityPersistence, EntityPersistence>()
.AutoRegister<IModelResolver, ModelResolver>()
.AutoRegister<IEntityAddition, EntityAddition>();
DbFactory.Reg(container);
}
#region 使用
/// <summary>创建模型数据表</summary>
/// <returns></returns>
public static IDataTable CreateTable()
{
return Container.Resolve<IDataTable>();
}
/// <summary>创建实体类的数据行访问器</summary>
/// <param name="entityType"></param>
/// <returns></returns>
public static IDataRowEntityAccessor CreateDataRowEntityAccessor(Type entityType)
{
return Container.ResolveInstance<IDataRowEntityAccessorProvider>().CreateDataRowEntityAccessor(entityType);
}
#endregion
}
}