public IEnumerable <IInterceptor> DetermineInterceptors(Type pluginType, Instance instance) { if (pluginType == typeof(IAppService)) { // DecoratorInterceptor is the simple case of wrapping one type with another // concrete type that takes the first as a dependency yield return(new FuncInterceptor <IAppService>(i => (IAppService) DynamicProxyHelper.CreateInterfaceProxyWithTargetInterface(typeof(IAppService), i))); } }
static void Main(string[] args) { var container = new Container(_ => { _.For <IAppService>() .DecorateAllWith( instance => (IAppService) DynamicProxyHelper.CreateInterfaceProxyWithTargetInterface(typeof(IAppService), instance)); _.For <IAppService>().Use <AppService1>(); }); var service = container.GetInstance <IAppService>(); service.DoWork(); container = new Container(_ => { _.For <IAppService>() .DecorateAllWith( instance => (IAppService) DynamicProxyHelper.CreateInterfaceProxyWithTargetInterface(typeof(IAppService), instance)); _.For <IAppService>().Use <AppService2>(); }); service = container.GetInstance <IAppService>(); service.DoWork(); container = new Container(_ => { _.Policies.Interceptors(new CustomInterception()); _.For <IAppService>().Use <AppService3>(); }); service = container.GetInstance <IAppService>(); service.DoWork(); Console.ReadKey(); }