public void TestSetUp() { var innerCatalog = new TypeCatalog(typeof(Customer)); var interceptor = new InterfaceInterceptor(); var valueInterceptor = new DynamicProxyInterceptor(interceptor); var cfg = new InterceptionConfiguration() .AddInterceptor(valueInterceptor); var catalog = new InterceptingCatalog(innerCatalog, cfg); container = new CompositionContainer(catalog); }
public UnityProvider(IDictionary<Type, object> map, int dbRetries, int dbSleepSeconds) { IMatchingRule alwaysMatch = new AlwaysMatchingRule(); _map = map; _container = new UnityContainer(); _retries = dbRetries; _sleepSeconds = dbSleepSeconds; IDictionary<Type, RetryOrHandleExceptionDelgate> exceptionTranslators = GetExceptionTranslators(map); _container.AddNewExtension<Interception>(); Interception inter = _container.Configure<Interception>(); if (inter == null) { Trace.WriteLine("No interception"); } PolicyDefinition definition = inter.AddPolicy("DbRetry"); if (definition == null) { Trace.WriteLine("No policy definition 0"); } if (definition.AddMatchingRule(alwaysMatch) == null) { Trace.WriteLine("No policy definition 1"); } _interceptor = new DbRetryInterceptor(dbRetries, dbSleepSeconds, exceptionTranslators); if (definition.AddCallHandler(_interceptor) == null) { Trace.WriteLine("No policy definition 2"); } IInstanceInterceptor _instanceInterceptor = new InterfaceInterceptor(); foreach (KeyValuePair<Type, object> entry in map) { _container.RegisterInstance(entry.Key, entry.Value); if (entry.Key.IsInterface) { _container.Configure<Interception>().SetInterceptorFor(entry.Key, _instanceInterceptor); } } }