VS - Microsoft.Practices.Unity
Posted 白马酒凉
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VS - Microsoft.Practices.Unity相关的知识,希望对你有一定的参考价值。
PM> Install-Package Unity
Web.config
<configSections> <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,Microsoft.Practices.Unity.Configuration" /> </configSections> <unity xmlns="http://schemas.microsoft.com/practices/2010/unity"> <container> <register type="Common.Interfaces.IGetTestBLL,Common" mapTo="R365.Common.BusinessLogic.GetDummyTestBLL,Common" /> </container> </unity>
UnityHelper.cs
using Microsoft.Practices.Unity; namespace VML.Employee.Common.Utils { public static class UnityHelper { private static IUnityContainer unityContainer = new UnityContainer(); static UnityHelper() { } public static IUnityContainer UnityContainer { get { return unityContainer; } set { unityContainer = value; } } public static T Resolve<T>(params ResolverOverride[] overrides) { return unityContainer.Resolve<T>(overrides); } public static T Resolve<T>(string name, params ResolverOverride[] overrides) { return unityContainer.Resolve<T>(name, overrides); } } }
IGetTestBLL.cs
public interface IGetTestBLL { List<Test> GetTestById(int id); }
GetTestBLL.cs
// get dummpy data public class GetDummyTestBLL : IGetTestBLL { public List<Test> GetTestById(int id) { ...
} } // get data from WebService public class GetWCFTestBLL : IGetTestBLL { public List<Test> GetTestById(int id) {
...
} }
UnityHelper.UnityContainer.LoadConfiguration();
IGetTestBLL getTest = UnityHelper.Resolve<IGetTestBLL>();
getTest.GetTestById(1);
以上是关于VS - Microsoft.Practices.Unity的主要内容,如果未能解决你的问题,请参考以下文章
什么是 Microsoft.Practices.EnterpriseLibrary.Data
使用 Microsoft.Practices.EnterpriseLibrary.Data IResultSetMapper<T>
是否有关于 2008 版 System.Windows.Forms ( Microsoft.Practices.CompositeUI ) 的文档
无法打开源“Microsoft.Practices.EnterpriseLibrary.Data”的日志。读取/写入事件日志时,您可能没有写入权限
getstoredproccommand(“procedurename”,new object [1])在Microsoft.Practices.EnterpriseLibrary.Data.dll中