/// <summary> /// Initializes a new instance of the <see cref="ConventionCatalog"/> class, using the provided array part registries. /// </summary> /// <param name="registries">An array of <see cref="IPartRegistry{T}"/> instance.</param> public ConventionCatalog(params IPartRegistry<IContractService>[] registries) { if (registries == null) { throw new ArgumentNullException("registries", "The registries parameter cannot be null."); } var cfg = new InterceptionConfiguration() .AddHandler(new ConventionPartHandler(registries)); this.interceptingCatalog = new InterceptingCatalog(new EmptyCatalog(), cfg); }
public void TestSetUp() { var typeCatalog = new TypeCatalog(typeof(CtorOrderProcessor), typeof(OrderProcessor), typeof(TestGenericContractRegistry)); var cfg = new InterceptionConfiguration().AddHandler(new GenericExportHandler()); var catalog = new InterceptingCatalog(typeCatalog, cfg); var provider = new CatalogExportProvider(catalog); provider.SourceProvider = provider; ExportProvider = provider; }
/// <summary> /// Initializes a new instance of the <see cref="FilteringCatalog"/> class. /// </summary> /// <param name="inner">A <see cref="ComposablePartCatalog"/> whose parts /// are to be filtered based on a given criteria.</param> /// <param name="filter">A filter query.</param> public FilteringCatalog(ComposablePartCatalog inner, Func<ComposablePartDefinition, bool> filter) { if (inner == null) throw new ArgumentNullException("inner"); if (filter == null) throw new ArgumentNullException("filter"); var cfg = new InterceptionConfiguration() .AddHandler(new FilteringPartHandler(filter)); this.interceptingCatalog = new InterceptingCatalog(inner, cfg); }
private static CompositionContainer CreateContainer1() { // Create source catalog, note we are passing the registry part. // During the runtime, GenericExportHandler will query this catalog for // all types implementing IGenericContractRegistry var typeCatalog = new TypeCatalog(typeof(Trampoline), typeof(MyGenericContractRegistry)); // Create the interception configuration and add support for open generics var cfg = new InterceptionConfiguration() .AddHandler(new GenericExportHandler()); // Create the InterceptingCatalog and pass the configuration var interceptingCatalog = new InterceptingCatalog(typeCatalog, cfg); // Create the container return new CompositionContainer(interceptingCatalog); }
public void Run() { Console.WriteLine("\n*** Interception Demo ***"); // Create source catalog var catalog = new TypeCatalog(typeof(Bar), typeof(Foo)); // Create interception configuration var cfg = new InterceptionConfiguration() // Add catalog wide startable interceptor .AddInterceptor(new StartableStrategy()) /* .AddInterceptionCriteria( new LogInterceptionCriteria( new DynamicProxyInterceptor( new LoggingInterceptor()))) */ // Add Castle DynamicProxy based logging interceptor for parts // which want to be logged, does exactly the same as the above code .AddInterceptionCriteria( new PredicateInterceptionCriteria( // Apply the interceptor only to parts which contain // Log export metadata which equals to true new DynamicProxyInterceptor(new LoggingInterceptor()), def => def.ExportDefinitions.First().Metadata.ContainsKey("Log") && def.ExportDefinitions.First().Metadata["Log"].Equals(true))); // Create the InterceptingCatalog with above configuration var interceptingCatalog = new InterceptingCatalog(catalog, cfg); // Create the container var container = new CompositionContainer(interceptingCatalog); // Bar part will be intercepted only by the startable strategy var barPart = container.GetExportedValue<IBar>(); barPart.Foo(); // Foo part will be intercepted by both startable and logging strategies var fooPart = container.GetExportedValue<IFoo>(); fooPart.Bar(); }
/// <summary> /// Initializes a new instance of the <see cref="GenericCatalog"/> class. /// </summary> /// <param name="catalog"><see cref="ComposablePartCatalog"/> from which <see cref="IGenericContractRegistry"/> instances will be retrieved.</param> /// <param name="registries">Additional registries.</param> public GenericCatalog(ComposablePartCatalog catalog, params IGenericContractRegistry[] registries) { var cfg = new InterceptionConfiguration() .AddHandler(new GenericExportHandler(registries)); this.interceptingCatalog = new InterceptingCatalog(catalog, cfg); }
public Request(ComposablePartCatalog parentCatalog, CompositionContainer parentContainer) { Console.WriteLine("/* Request */"); // Create interception configuration with non-shared parts filter var cfg = new InterceptionConfiguration() .AddHandler(new PartCreationPolicyFilter(CreationPolicy.NonShared)); // Create the InterceptingCatalog with above configuration var interceptingCatalog = new InterceptingCatalog(parentCatalog, cfg); // Create the child container this.requestContainer = new CompositionContainer(interceptingCatalog, parentContainer); }