首页 > 代码库 > VS - Microsoft.Practices.Unity
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。