以下的代码麻烦熟悉的朋友帮助添加一下注释,最好是能详细一些,我对依赖注入这一块有些了解而已,实在是有点看不太明白.非常谢谢!
private static readonly TransparentProxyInterceptor injector = new TransparentProxyInterceptor();
public static IUnityContainer Container
{ get; private set; }
static ServiceLoader()
{
UnityConfigurationSection unitySection = ConfigurationManager.GetSection("unity") as UnityConfigurationSection;
if (unitySection == null)
{
throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, "Missing Unity configuration section."));
}
Container = new UnityContainer();
UnityContainerElement containerElement;
containerElement = unitySection.Containers.Default;
containerElement.Configure(Container);
Container.AddNewExtension<Interception>();
}
public static T LoadService<T>()
{
Container.Configure<Interception>().SetDefaultInterceptorFor(typeof(T), injector);
return Container.Resolve<T>();
}
public static T LoadService<T>(string serviceName)
{
Container.Configure<Interception>().SetDefaultInterceptorFor(typeof(T), injector);
return Container.Resolve<T>(serviceName);
}
这段代码用的是MS的Unity框架吧
用注释不太好描述清楚
建议你看看这篇文章,是讲Unity的,写的很好,相信你看完之后就明白了
http://www.cnblogs.com/Terrylee/archive/2008/02/21/unity-application-block-part1.html
看不懂~!飘过