-
using System.Configuration;
-
using System.Globalization;
-
using Microsoft.Practices.Unity;
-
using Microsoft.Practices.Unity.Configuration;
-
using Microsoft.Practices.Unity.InterceptionExtension;
-
using System.Web;
-
using System;
-
-
namespace Common
-
{
-
public static class ServiceLocator
-
{
-
// private static readonly InterfaceInterceptor injector = new InterfaceInterceptor ();
-
-
private static readonly TransparentProxyInterceptor injector = new TransparentProxyInterceptor();
-
-
public static IUnityContainer Container
-
{
-
get;
-
private set;
-
}
-
static ServiceLocator()
-
{
-
Container = new UnityContainer();
-
UnityConfigurationSection unitySection = ConfigurationManager.GetSection("unity") as UnityConfigurationSection;
-
if (unitySection == null)
-
{
-
throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture,"missing unity configuration section"));
-
}
-
Container.AddNewExtension<Interception>();
-
-
unitySection.Configure(Container,"Container");
-
-
}
-
///
-
/// 没?有D为a映3射?指?定¨别e名?
-
/// name属?性?没?有D赋3值μ
-
///
-
///
-
///
-
public static T LoadService
()
-
{
-
Container.Configure<Interception>().SetDefaultInterceptorFor
(injector);
-
return Container.Resolve
();
-
}
-
///
-
/// 为a映3射?指?定¨别e名?
-
/// name属?性?赋3值μ
-
///
-
///
-
///
-
///
-
public static T LoadService
(
string serviceName)
-
{
-
Container.Configure<Interception>().SetDefaultInterceptorFor
(injector);
-
return Container.Resolve
(serviceName);
-
}
-
}
-
}
-