/// <summary> /// 执行API方法 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="method"></param> /// <returns></returns> public async Task <T> Execute <T>(MethodBase <T> method) { //将方法在策略中包装 var m = (MethodBase <T>)PolicyInjection.Wrap(method.GetType(), method); return(await m.Execute(this)); }
public static object GetObject(Type type, AbstractDatabase Db, IUnityContainer _container, ICacheManager _cache, string _pluginName, string unityname) { //if (Db == null) //{ // EFWCoreLib.CoreFrame.DbProvider.AbstractDatabase Rdb = EFWCoreLib.CoreFrame.DbProvider.FactoryDatabase.GetDatabase(); // //SysLoginRight currLoginUser = (SysLoginRight)EFWCoreLib.CoreFrame.Init.AppGlobal.cache.GetData("RoleUser"); // //Rdb.WorkId = currLoginUser.WorkId; // Db = Rdb; // _container = EFWCoreLib.CoreFrame.Init.AppGlobal.container; //} //读unity配置文件把类注入到接口得到对象实例 IUnityContainer container = _container; Object t = null; if (unityname == null) { t = container.Resolve(type); } else { t = container.Resolve(type, unityname); } IbindDb ibind = (IbindDb)t; ibind.BindDb(Db, container, _cache, _pluginName); //给对象加上代理 t = PolicyInjection.Wrap(t.GetType(), t); return(t); }
public object GetInstance(InstanceContext instanceContext, Message message) { Type serviceType = instanceContext.Host.Description.ServiceType; object serviceInstance = Activator.CreateInstance(serviceType); serviceInstance = PolicyInjection.Wrap(this._serviceContractType, serviceInstance); return(serviceInstance); //PolicyInjector policyInjector = null; //if (string.IsNullOrEmpty(this._policyInjectorName)) //{ // policyInjector = new PolicyInjectorFactory().Create(); //} //else //{ // policyInjector = new PolicyInjectorFactory().Create(this._policyInjectorName); //} //Type serviceType = instanceContext.Host.Description.ServiceType; //object serviceInstance = Activator.CreateInstance(serviceType); //if (!this._serviceContractType.IsInterface && !serviceType.IsMarshalByRef && policyInjector is RemotingPolicyInjector) //{ // return serviceInstance; //} //return policyInjector.Wrap(serviceInstance, this._serviceContractType); }
/// <summary> /// GetInstance is used to create an instance of ProjectService wrapped by the PolicyInjection framework. /// </summary> /// <param name="instanceContext"></param> /// <param name="message"></param> /// <returns>Contract.IProjectService</returns> public object GetInstance(System.ServiceModel.InstanceContext instanceContext, System.ServiceModel.Channels.Message message) { // Start client connection to database. var context = EntityContext.CreateInstance(_connectionStringName); context.Open(); // Return indexer service. return(PolicyInjection.Wrap <Contract.IProjectService>( new ProjectService(context, context.Identity))); }
/// <summary> /// This function demostrates EntLib Policy Injection usage. No actual use. /// 关于使用EntLib的PolicyInjection的几点说明[重要总结] /// # 需要添加Unity.*.dll的引用 /// # 添加Reference时,确保EnterpriseLibrary.*.dll和Unity.*.dll是来自同一份EntLib安装的文件,因为前者对后者有依赖,版本信息必须严格匹配 /// </summary> static partial void InitPolicyInjection() { // PolicyInjection: A static facade class that provides the main entry point into the Policy Injection Application Block. Methods on this class create intercepted objects, or wrap existing instances with interceptors. // // The interception handler is defined in Web.config var obj = new ClinicalPathwayInstance(); IComparable proxy = PolicyInjection.Wrap <IComparable>(obj); //or PolicyInjection.Create<ClinicalPathwayInstance,IComparable> proxy.CompareTo(null); }
public object GetInstance(System.ServiceModel.InstanceContext instanceContext, System.ServiceModel.Channels.Message message) { Type serviceType = instanceContext.Host.Description.ServiceType; object serviceInstance = Activator.CreateInstance(serviceType); if (!this._serviceContractType.IsInterface && !serviceType.IsMarshalByRef && string.IsNullOrEmpty(this._policyInjectorName)) { return(serviceInstance); } return(PolicyInjection.Wrap(this._serviceContractType, serviceInstance)); }
private void SaveCustomer(CustomerForm dialog) { try { ICustomer ic = PolicyInjection.Wrap <ICustomer>(dialog); ic.Save(); RefreshCustomers(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void CanWrapObjectWithInterceptionAttributes() { GlobalCountCallHandler.Calls.Clear(); WrappableWithAttributes wrappable = PolicyInjection.Wrap <WrappableWithAttributes>(new WrappableWithAttributes()); wrappable.Method(); wrappable.Method(); wrappable.Method3(); Assert.AreEqual(2, GlobalCountCallHandler.Calls.Count); Assert.AreEqual(2, GlobalCountCallHandler.Calls["Method"]); Assert.AreEqual(1, GlobalCountCallHandler.Calls["Method3"]); }
public void CanWrapObjectWithInterceptionAttributesWithNonGenericMethods() { GlobalCountCallHandler.Calls.Clear(); WrappableWithAttributes wrappable = (WrappableWithAttributes)PolicyInjection.Wrap(typeof(WrappableWithAttributes), new WrappableWithAttributes()); wrappable.Method(); wrappable.Method(); wrappable.Method3(); Assert.AreEqual(2, GlobalCountCallHandler.Calls.Count); Assert.AreEqual(2, GlobalCountCallHandler.Calls["Method"]); Assert.AreEqual(1, GlobalCountCallHandler.Calls["Method3"]); }
/// <summary> /// 获取认证信息 /// </summary> /// <param name="user"></param> /// <param name="pwd"></param> /// <returns></returns> private static Auth GetAuth(string user, string pwd) { var auth = AuthDataPersistence.Load(user); if (auth == null) { auth = PolicyInjection.Create <Auth>(user, pwd); } else { auth = PolicyInjection.Wrap <Auth>(auth); //auth 在某些属性更改的时候,会自动保存,如果保存时密码错了,就一直是错的, //所以要在这里更新密码 auth.Pwd = pwd; } return(auth); }
static void Main(string[] args) { IMyRepository repo = new MyRepository(); IMyRepository proxyRepo = PolicyInjection.Wrap <IMyRepository>(repo); var allProducts = proxyRepo.GetAllProducts(); foreach (var product in allProducts) { Console.WriteLine("Product: {0}", product.Name); } Console.WriteLine(); var nexus4 = proxyRepo.GetProduct(3); Console.WriteLine("Product with Id=3: is {0}", nexus4.Name); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
/// <summary> /// Creates a WCF entity service that is wrapped by the Enterprise Library /// policy injection. /// </summary> /// <typeparam name="T">Represents the type of entity service to create.</typeparam> /// <returns>IServiceHost</returns> public static IServiceHost CreateInstance <T>() { return(PolicyInjection.Wrap <IServiceHost>(new ServiceHost <T>())); }
public async Task <T> Execute <T>(MethodBase <T> method) where T : class { var m = (MethodBase <T>)PolicyInjection.Wrap(method.GetType(), method); return(await m.Execute(this.Auth)); }
public async Task <string> GetResult(MethodBase method) { var m = (MethodBase)PolicyInjection.Wrap(method.GetType(), method); return(await m.GetResult(this.Auth)); }
public async Task <string> GetResult <T>(T method) where T : MethodBase { var m = PolicyInjection.Wrap <T>(method); return(await m.GetResult(this.Auth)); }
/// <summary> /// Creates an entity context singleton that is wrapped by the Enterprise Library /// policy injection. /// </summary> /// <param name="connectionStringName">A valid <see cref="System.Uri"/> instance /// using the <c>db4o://</c> scheme.</param> /// <returns>IEntityContext</returns> public static IEntityContext CreateInstance(string connectionStringName) { return(PolicyInjection.Wrap <IEntityContext>(new EntityContext(connectionStringName))); }
/// <summary> /// Creates a Db4o database server singleton that is wrapped by the Enterprise Library /// policy injection. /// </summary> /// <returns>IDatabaseServer</returns> public static IDatabaseServer CreateInstance() { return(PolicyInjection.Wrap <IDatabaseServer>(new DatabaseServer())); }