在Web.config里面的有一段appSettings设置
<appSettings>
<!-- Pet Shop DAL configuration settings -->
<add key="WebDAL" value="PetShop.SQLServerDAL"/>
<add key="OrdersDAL" value="PetShop.SQLServerDAL"/>
<add key="ProfileDAL" value="PetShop.SQLProfileDAL"/>
……
<add key="Event Log Source" value=".NET Pet Shop 4.0"/>
</appSettings>
通过private static readonly string path = ConfigurationManager.AppSettings["WebDAL"];获取相应程序集的引用路径,
然后string className = path + ".Category";获取要引用的命名空间
最后通过反射return (PetShop.IDAL.ICategory)Assembly.Load(path).CreateInstance(className);
获取一个实例(被强类型转换成PetShop.IDAL.ICategory类型)