Mercurial > pub > ImplabNet
diff Implab.Playground/Program.cs @ 278:6691aff01de1 v3
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
Implab.ServiceHost: rewritten TypeReference (added support for nested types), stable API
author | cin |
---|---|
date | Thu, 03 May 2018 09:59:44 +0300 |
parents | 963b17c275be |
children | 8714471e8d78 |
line wrap: on
line diff
--- a/Implab.Playground/Program.cs Sat Apr 28 18:48:09 2018 +0300 +++ b/Implab.Playground/Program.cs Thu May 03 09:59:44 2018 +0300 @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using Implab.Components; using Implab.Diagnostics; using Implab.ServiceHost.Unity; using Implab.Xml; @@ -29,11 +30,39 @@ } + public class FooFactory : IFactory<Foo>, IFactory<Foo.Bar> { + + public bool UseSsl { get; set; } + + public string Connection { get; set; } + + public Foo Create() { + return new Foo() { + Name = "AutoFac" + }; + } + + Foo.Bar IFactory<Foo.Bar>.Create() { + return new Foo.Bar(); + } + } + public interface IContainer<T> { T Instance { get; set; } } public class Container<T> : IContainer<T> { + public class Bar { + + } + + public class Bar<T2> { + public class Baz { + + } + + } + public Container() { } @@ -65,29 +94,22 @@ source.Switch.Level = SourceLevels.All; source.Listeners.Add(listener); - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - var ctx = new ContainerBuilder(); - - Console.WriteLine($"Created: {stopwatch.ElapsedMilliseconds}"); - stopwatch.Restart(); - - ctx.LoadConfig("data/sample.xml"); - - Console.WriteLine($"Loaded: {stopwatch.ElapsedMilliseconds}"); + var resolver = new TypeResolver(); + resolver.AddNamespace("System"); + resolver.AddNamespace("System.Collections.Generic"); + resolver.AddNamespace("Implab.Playground"); + resolver.AddMapping("string", typeof(string)); + resolver.AddMapping("listOf`1", typeof(List<>)); - var container = ctx.Container; + var spec = TypeReference.Parse("Container{listOf{string}}+Bar{List{string}}"); - stopwatch.Restart(); - var instace1 = container.Resolve<IContainer<string>>(); - Console.WriteLine($"Resolved1: {stopwatch.ElapsedMilliseconds}"); + var t = resolver.Resolve(spec, true); - stopwatch.Restart(); - var instace2 = container.Resolve<IContainer<Foo>>(); - Console.WriteLine($"Resolved2: {stopwatch.ElapsedMilliseconds}"); - - DisplayContainerRegistrations(container); + Console.WriteLine("{0}", t); + Console.WriteLine("Spec: {0}", spec); + Console.WriteLine("IsGenericType: {0}", t.IsGenericType); + Console.WriteLine("IsGenericTypeDefinition: {0}", t.IsGenericTypeDefinition); + Console.WriteLine("ContainsGenericParameters: {0}", t.ContainsGenericParameters); } static void DisplayContainerRegistrations(IUnityContainer theContainer) {