Autofac IContainer 测试
2016-06-08 05:11
316 查看
using Autofac; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AutofacDemo { public interface ITest { string Hello1(); } public class Test1 : ITest { public string Hello1() { Console.WriteLine("ok1"); return "ok11"; } } public class Test2 : ITest { public string Hello1() { Console.WriteLine("ok2"); return "ok22"; } } class Program { private static IContainer Container1 { get; set; } private static IContainer Container2 { get; set; } static void Main(string[] args) { var builder3 = new ContainerBuilder(); builder3.RegisterType<Test1>().As<ITest>(); var Container3 = builder3.Build(); var builder1 = new ContainerBuilder(); builder1.RegisterType<Test1>().As<ITest>(); var Container1 = Container3;// builder1.Build(); var builder2 = new ContainerBuilder(); builder2.RegisterType<Test2>().As<ITest>(); var Container2 = Container3;// builder2.Build(); //using (var scope = Container1.BeginLifetimeScope()) //{ // var test1 = scope.Resolve<ITest>(); // test1.Hello1(); //} //using (var scope = Container2.BeginLifetimeScope()) //{ // var test2 = scope.Resolve<ITest>(); // test2.Hello1(); //} var test1 = Container1.Resolve<ITest>(); test1.Hello1(); var test2 = Container2.Resolve<ITest>(); test2.Hello1(); Console.WriteLine(Container1.GetHashCode()); Console.WriteLine(Container2.GetHashCode()); } } }
结果是这两个hashcode相等
Console.WriteLine(Container1.GetHashCode()); Console.WriteLine(Container2.GetHashCode());
相关文章推荐
- CodeForces 667A Pouring Rain
- 游戏中的AI算法总结与改进
- ERROR [main] zookeeper.RecoverableZooKeeper: ZooKeeper exists failed after 4 attempts
- 判断Set中课程是否存在,Contains方法
- LeetCode 11 Container With Most Water
- TurboMail邮件系统邮件归档模块介绍
- hdu1532-Drainage Ditches
- Avoid on a Thank-You Email
- Contains Duplicate III
- Contains Duplicate II
- CodeForces 675B Restoring Painting
- 219.[Leetcode]Contains Duplicate II
- Airbnb
- Contains Duplicate II
- 336. Palindrome Pairs
- Contains Duplicate
- spark博客 http://www.cnblogs.com/cenyuhai/p/3537249.html Spark作业调度
- POJ 1273 Drainage Ditches (最大流)
- Codeforces #353(div2)B.Restoring Painting
- volley(4) 请求参数:data:[ { bar_remain:XX , bar_code:"XX" , bar_id: XX}], method:GET