Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Composition;
- using System.Composition.Hosting;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- class Program
- {
- [Export]
- public sealed class A
- {
- [Import]
- public B B { get; set; }
- [OnImportsSatisfied]
- public void OnImportsSatisfied()
- {
- Console.WriteLine("From A");
- }
- }
- [Export]
- public sealed class B
- {
- [Import]
- public C C { get; set; }
- [OnImportsSatisfied]
- public void OnImportsSatisfied()
- {
- Console.WriteLine("From B");
- }
- }
- [Export]
- public sealed class C
- {
- [OnImportsSatisfied]
- public void OnImportsSatisfied()
- {
- Console.WriteLine("From C");
- }
- }
- static void Main(string[] args)
- {
- using(var container = new ContainerConfiguration().WithAssembly(Assembly.GetAssembly(typeof(A))).CreateContainer())
- {
- container.GetExport<A>();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement