コード例 #1
0
        private void InitDependency()
        {
            //依赖服务配置
            Container = new AyxContainer();
            Container.Wire <ITestDataRepo, TestDataRepo>();
            Container.WireSingleton <ILogger, SimpleLogger>();

            //使用自带的容器创建View和ViewModel的容器
            VM = new AvalonContainer(new DefaultContainer(Container));
            //View和ViewModel依赖配置
            VM.WireVM <MainWindow, MainWindowViewModel>();
            VM.WireVM <TestOneView, TestOneViewModel>();
        }
コード例 #2
0
        public void TokenTest()
        {
            var di = new AyxContainer();

            di.Wire <ITest, TestA>("a");
            di.Wire <ITest, TestB>("b");

            var a    = di.Get <ITest>("a");
            var b    = di.Get <ITest>("b");
            var test = di.Get <ITest>();

            Assert.AreEqual("TestA", a.Show());
            Assert.AreEqual("TestB", b.Show());
            Assert.IsNotNull(test);
        }
コード例 #3
0
        public void ConstructureInjectionTest()
        {
            var di = new AyxContainer();

            di.Wire <IComputer, AddComputer>();
            di.WireSingleton <Logger>();

            var test   = di.Get <InjectModel>();
            var result = test.Compute(4, 5);

            Assert.AreEqual(9, result);

            var text     = "test";
            var expected = "console:" + text;
            var actual   = test.Log(text);

            Assert.AreEqual(expected, actual);
        }
コード例 #4
0
        public void WireTest()
        {
            var di = new AyxContainer();

            Assert.AreEqual(di.Count, 0);
            di.Wire <ITest, TestA>();
            Assert.AreEqual(di.Count, 1);
            di.Wire <TestB>();
            Assert.AreEqual(di.Count, 2);

            var a1 = di.Get <ITest>();
            var a2 = di.Get <ITest>();

            Assert.AreNotSame(a1, a2);

            var b1 = di.Get <TestB>();
            var b2 = di.Get <TestB>();

            Assert.AreNotSame(b1, b2);
        }
コード例 #5
0
        public void WireSingletonTest()
        {
            var di     = new AyxContainer();
            var single = new TestA();

            di.WireSingleton(single);
            var actual = di.Get <TestA>();

            Assert.AreSame(single, actual);

            di.WireSingleton <TestB>();
            var b1 = di.Get <TestB>();
            var b2 = di.Get <TestB>();

            Assert.AreSame(b1, b2);

            di.WireSingleton <IComputer, AddComputer>();
            var computer1 = di.Get <IComputer>();
            var computer2 = di.Get <IComputer>();

            Assert.AreSame(computer1, computer2);
        }