Mercurial > pub > ImplabNet
diff Implab.Playground/Program.cs @ 272:9d1cca834b05 v3
preview version of Unity xml configuration
author | cin |
---|---|
date | Thu, 26 Apr 2018 03:14:54 +0300 |
parents | d4d437ec4483 |
children | 79110a16cab7 |
line wrap: on
line diff
--- a/Implab.Playground/Program.cs Wed Apr 25 19:23:35 2018 +0300 +++ b/Implab.Playground/Program.cs Thu Apr 26 03:14:54 2018 +0300 @@ -1,10 +1,12 @@ using System; using System.Diagnostics; +using System.Linq; using Implab.Diagnostics; using Implab.ServiceHost.Unity; using Implab.Xml; using Unity; using Unity.Injection; +using Unity.Registration; namespace Implab.Playground { @@ -22,7 +24,11 @@ } - public class Container<T> { + public interface IContainer<T> { + T Instance { get; set; } + } + + public class Container<T> : IContainer<T> { public Container() { } @@ -49,8 +55,30 @@ ctx.Visit(conf); - Console.WriteLine($"Registrations: {conf.Items.Count}"); + DisplayContainerRegistrations(container); + + var instace1 = container.Resolve<IContainer<string>>(); + var instace2 = container.Resolve<IContainer<Foo>>(); + + } + static void DisplayContainerRegistrations(IUnityContainer theContainer) { + string regName, regType, mapTo, lifetime; + Console.WriteLine("Container has {0} Registrations:", + theContainer.Registrations.Count()); + foreach (ContainerRegistration item in theContainer.Registrations) { + regType = item.RegisteredType.FullName; + mapTo = item.MappedToType.FullName; + regName = item.Name ?? "[default]"; + lifetime = item.LifetimeManager.LifetimeType.Name; + if (mapTo != regType) { + mapTo = " -> " + mapTo; + } else { + mapTo = string.Empty; + } + lifetime = lifetime.Substring(0, lifetime.Length - "LifetimeManager".Length); + Console.WriteLine("+ {0}{1} '{2}' {3}", regType, mapTo, regName, lifetime); + } }