using My.OA.IDAL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace My.OA.DALFactory
{
public class AbstractFactory
{
private static readonly string AssemblyPath = ConfigurationManager.AppSettings["AssemblyPath"];
private static readonly string NameSpace = ConfigurationManager.AppSettings["NameSpace"];
public static IUserInfoDal CreateUserInfoDal()
{
string fullName = NameSpace + ".UserInfoDal";
return CreateInstance(fullName) as IUserInfoDal;
}
private static object CreateInstance(string fullName)
{
Assembly ass = Assembly.Load(AssemblyPath);
return ass.CreateInstance(fullName);
}
}
}
在App.config里面增加程序集得设置
<appSettings>
<add key="AssemblyPath" value="My.OA.DAL"/>
<add key="NameSpace" value="My.OA.DAL"/>
</appSettings>