Ejemplo n.º 1
0
        public void ResolveMultipelWithScope()
        {
            var builder = new IocBuilder();

            builder.RegisterSingleton <IA, A>();
            builder.Register <IB, B>();
            builder.Register <IC, C>();
            builder.Register <ID, D>();
            builder.Register <ID, D>();
            builder.RegisterPerScope <ID, D>();


            builder.Register <IF, F>();
            var container = builder.Build();

            IEnumerable <ID> d1;

            using (var scope = container.Scope)
            {
                d1 = scope.Resolve <IEnumerable <ID> >();
                var d2 = scope.Resolve <IEnumerable <ID> >();
                //Assert.AreNotEqual(d1.FirstOrDefault().GetHashCode(), d2.LastOrDefault().GetHashCode());
                Assert.AreEqual(d1.LastOrDefault(), d2.LastOrDefault());
            }
            var d3 = container.Resolve <IEnumerable <ID> >();

            Assert.AreNotEqual(d1.FirstOrDefault(), d3.LastOrDefault());
            Assert.AreNotEqual(d1.LastOrDefault(), d3.LastOrDefault());
        }
Ejemplo n.º 2
0
        public void ResolveMultipleWithSingletonAndMatch()
        {
            var builder = new IocBuilder();

            builder.RegisterSingleton <IA, A>().Match <A>();
            builder.Register <IB, B>();
            builder.Register <IC, C>();
            builder.Register <ID, D>();
            builder.Register <ID, D>();
            builder.RegisterSingleton <ID, D>().Match <D>();
            builder.Register <IF, F>();
            var container = builder.Build();

            var f1 = container.Resolve <IF>();
            var f2 = container.Resolve <IF>();
            var a  = container.Resolve <A>();
            var d  = container.Resolve <D>();

            Assert.AreNotEqual(f1, f2);
            Assert.AreNotEqual(f1.Ds.FirstOrDefault().B, f2.Ds.FirstOrDefault().B);

            Assert.AreEqual(f1.Ds.FirstOrDefault().A, f2.Ds.FirstOrDefault().A);
            CollectionAssert.AreEqual(f1.Ds.Select(c => c.A).ToArray(), f2.Ds.Select(c => c.A).ToArray());
            Assert.AreEqual(f1.Ds.FirstOrDefault().A, a);
            Assert.AreEqual(f1.Ds.LastOrDefault(), d);
        }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            XmlConfigurator.Configure();
            var container = IocBuilder.Build();

            SetupCommandLineOptions(args, container);
            StartSpeedtest(container);
        }
Ejemplo n.º 4
0
 protected void Application_Start()
 {
     IocBuilder.Build();
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
 }
Ejemplo n.º 5
0
        public void MissingRegistrationThrowsExceptionOnContainerBuild()
        {
            var builder = new IocBuilder();

            builder.Register <IA, A>();
            builder.Register <IC, C>();
            builder.Register <ID, D>();
            var container = builder.Build();
        }
Ejemplo n.º 6
0
        public void RegisterResolveKeyedFunc()
        {
            var builder = new IocBuilder();

            builder.Register(c => new Func <string>(() => "hello")).IdentifiedAs("test");
            var container = builder.Build();

            var func = container.ResolveWithId <Func <string> >("test");

            Assert.AreEqual("hello", func());
        }
Ejemplo n.º 7
0
        public void ResolveSelfRegistered()
        {
            var builder = new IocBuilder();

            builder.Register <A, A>();
            var container = builder.Build();

            var a = container.Resolve <A>();
            var b = container.Resolve <A>();

            Assert.AreNotEqual(a, b);
        }
Ejemplo n.º 8
0
        public void ResolveSingletonLambda()
        {
            var builder = new IocBuilder();

            builder.RegisterSingleton <IA>(c => new A());
            var container = builder.Build();

            var a1 = container.Resolve <IA>();
            var a2 = container.Resolve <IA>();

            Assert.AreEqual(a1, a2);
        }
Ejemplo n.º 9
0
        public void SimpleResolve()
        {
            var builder = new IocBuilder();

            builder.Register <IA, A>();

            var container = builder.Build();

            var a = container.Resolve <IA>();
            var b = container.Resolve <IA>();

            Assert.AreNotEqual(a, b);
        }
Ejemplo n.º 10
0
        public void ResolveMultipleOfSameType()
        {
            var builder = new IocBuilder();

            builder.Register <IA, A>();
            builder.Register <IA, A>();
            var container = builder.Build();

            var a = container.Resolve <IEnumerable <IA> >().ToArray();

            Assert.AreEqual(2, a.Count());
            Assert.AreNotEqual(a[0], a[1]);
        }
Ejemplo n.º 11
0
        public void ResolveKeyed()
        {
            var builder = new IocBuilder();

            builder.Register <G, G>();
            builder.RegisterSingleton <IA, A>().IdentifiedAs("test");
            var container = builder.Build();

            var g = container.Resolve <G>();
            var a = container.ResolveWithId <IA>("test");

            Assert.AreEqual(g.A, a);
        }
Ejemplo n.º 12
0
        public void ResolveLambda()
        {
            var builder = new IocBuilder();

            builder.Register <IA, A>();
            builder.Register <IC>(c => new C(c.Resolve <IA>(), c.Resolve <IB>()));
            builder.Register <IB, B>();
            var container = builder.Build();

            var ic = container.Resolve <IC>();
            var id = container.Resolve <IC>();

            Assert.AreNotEqual(ic, id);
        }
Ejemplo n.º 13
0
        public void AdvancedResolveWithSingletonLambda()
        {
            var builder = new IocBuilder();

            builder.Register <IA, A>();
            builder.RegisterSingleton <IB>(c => new B());
            builder.Register <IC, C>();
            var container = builder.Build();

            var a = container.Resolve <IC>();
            var b = container.Resolve <IC>();

            Assert.AreEqual(a.B, b.B);
        }
Ejemplo n.º 14
0
        public void AdvancedResolve()
        {
            var builder = new IocBuilder();

            builder.Register <IA, A>();
            builder.Register <IB, B>();
            builder.Register <IC, C>();
            var container = builder.Build();

            var a = container.Resolve <IC>();
            var b = container.Resolve <IC>();

            Assert.AreNotEqual(a, b);
        }
Ejemplo n.º 15
0
        public void ResolveMultipleOfSameTypeAsParameter()
        {
            var builder = new IocBuilder();

            builder.Register <IA, A>();
            builder.Register <IB, B>();
            builder.Register <IC, C>();
            builder.Register <ID, D>();
            builder.Register <ID, D>();
            builder.Register <IF, F>();
            var container = builder.Build();

            var f1 = container.Resolve <IF>();
        }
Ejemplo n.º 16
0
        public void ResolveEnumerableSingletonWithMatch()
        {
            var builder = new IocBuilder();

            builder.RegisterSingleton <IA, A>().Match <A>();
            var container = builder.Build();

            var a3 = container.Resolve <IEnumerable <A> >();
            var a1 = container.Resolve <IA>();
            var a2 = container.Resolve <IA>();

            Assert.AreEqual(a1, a2);
            Assert.AreEqual(a2, a3.FirstOrDefault());
        }
Ejemplo n.º 17
0
        public void Configure <T>() where T : IConfigurator, new()
        {
            var config = new T();

            var builder = new MiddlewareBuilder();

            config.Configure(builder);
            middleware = builder.Build();

            var iocBuilder = new IocBuilder();

            config.ConfigureServices(iocBuilder);
            Services = iocBuilder.Build();
        }
Ejemplo n.º 18
0
        public void ResolveSingletonWithMatch()
        {
            var builder = new IocBuilder();

            builder.RegisterSingleton <IA, A>().Match <A>();
            var container = builder.Build();

            var a1 = container.Resolve <IA>();
            var a2 = container.Resolve <IA>();
            var a3 = container.Resolve <A>();

            Assert.AreEqual(a1, a2);
            Assert.AreEqual(a2, a3);
        }
Ejemplo n.º 19
0
        public void DeepObjectGraphWithWrongOrderResolve()
        {
            var builder = new IocBuilder();

            builder.Register <ID, D>();
            builder.Register <IA, A>();
            builder.Register <IC, C>();
            builder.Register <IB, B>();
            var container = builder.Build();

            var d = container.Resolve <ID>();
            var e = container.Resolve <ID>();

            Assert.AreNotEqual(d, e);
        }
Ejemplo n.º 20
0
        public void DeepObjectGraphWithWrongOrderAndSingletonResolve()
        {
            var builder = new IocBuilder();

            builder.RegisterSingleton <ID, D>();
            builder.Register <IA, A>();
            builder.Register <IC, C>();
            builder.Register <IB, B>();
            var container = builder.Build();

            var d1 = container.Resolve <ID>();
            var d2 = container.Resolve <ID>();

            Assert.AreEqual(d1, d2);
        }
Ejemplo n.º 21
0
        public void ScopeDisposesResolvedComponents()
        {
            var builder = new IocBuilder();

            builder.Register <E, E>();

            var container = builder.Build();

            E a = null;

            using (var scope = container.Scope)
            {
                a = scope.Resolve <E>();
                Assert.IsFalse(a.IsDisposed);
            }
            Assert.IsTrue(a.IsDisposed);
        }
Ejemplo n.º 22
0
        public CedrusGame(IocBuilder builder)
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            builder.LogRegistrations();
            builder.RegisterModules(Assembly.GetExecutingAssembly(), type => type.FullName.EndsWith("Module"));

            builder.RegisterSingleton(c => graphics.GraphicsDevice);
            builder.RegisterSingleton(c => new GameSettings(Window));
            builder.RegisterSingleton(c => Content);
            EnumerateAssemblies(assembly => builder.RegisterSingletonSubclassesOf(assembly, typeof(CommonAssetBuilder)));

            container = builder.Build();

            gameTimeline = container.Resolve <GameTimeline>();
            Appender     = container.Resolve <IAppender>()[GetType()];
        }
Ejemplo n.º 23
0
 public List <Vehicle> GetVehicleList()
 {
     return(IocBuilder.Build().Resolve <IVehicleProvider>().GetVehicleList());
 }