示例#1
0
        protected override void Configure()
        {
            _container = new SimpleContainer();

            _container.RegisterSingleton(typeof(MainWindowViewModel), "MainWindowViewModel", typeof(MainWindowViewModel));

            _container.RegisterInstance(typeof(IWindowManager), null, new WindowManager());
            _container.RegisterInstance(typeof(SimpleContainer), null, _container);
        }
示例#2
0
        public void ResolvableWithInstance()
        {
            var c = new SimpleContainer();

            c.RegisterInstance("ala ma kota"); // rejestruje instancję string
            // jest ok, zarejestrowano instancję string więc rozwikłanie konstruktora X jest możliwe
            c.Resolve <ConcreteWithStringParam>();
        }
示例#3
0
 protected override void Configure()
 {
     container = new SimpleContainer();
     container.Singleton <IWindowManager, WindowManager>();
     container.RegisterInstance(typeof(IDialogService), null,
                                new DialogService(dialogTypeLocator: new DialogTypeLocator()));
     container.PerRequest <MainViewModel>();
 }
示例#4
0
        public void ResolvingConstructorsDependency()
        {
            SimpleContainer c = new SimpleContainer();

            c.RegisterType <Baz1>(false);
            Assert.ThrowsException <Exception>(() => { c.Resolve <Baz1>(); });

            c.RegisterInstance <int>(1);
            c.RegisterInstance <string>("str");
            c.RegisterType <Baz2>(false);
            c.RegisterType <Baz3>(false);

            var b = c.Resolve <Baz1>();

            Assert.IsNotNull(b);
            Assert.IsTrue(b is Baz1);
        }
示例#5
0
        public void ResolvableWithInstance()
        {
            var c = new SimpleContainer();

            c.RegisterInstance("ala ma kota"); // rejestruje instancję string
            // jest ok, zarejestrowano instancję string więc rozwikłanie konstruktora X jest możliwe
            c.Resolve<ConcreteWithStringParam>();
        }
        public void FactoryTest()
        {
            SimpleContainer container = new SimpleContainer();

            container.RegisterInstance <string>("Something");
            NotifierFactory.SetProvider(() => container.Resolve <Notifier>());
            DoTest();
        }
示例#7
0
        public void ClassWithOneAttributedConstructor()
        {
            SimpleContainer c = new SimpleContainer();

            c.RegisterInstance <string>("abc");
            ClassWithOneAttributedConstructor a = c.Resolve <ClassWithOneAttributedConstructor>();

            Assert.AreEqual(a.s, "");
        }
示例#8
0
        public static void RegisterInstance(object implementation)
        {
            SimpleContainer _container = (SimpleContainer)IoC.GetInstance(typeof(SimpleContainer), null);

            Type type = implementation.GetType();

            _container.UnregisterHandler(type, null);
            _container.RegisterInstance(type, null, implementation);
        }
示例#9
0
        public void RegisterInstance()
        {
            var c = new SimpleContainer();

            var foo1 = new ConcreteType();
            c.RegisterInstance<ITypeToResolve>(foo1);
            var foo2 = c.Resolve<ITypeToResolve>();
            Assert.AreSame(foo1, foo2);
        }
示例#10
0
        public void RegisterFrame(Frame frame)
        {
            _navigationService = new FrameAdapter(frame);

            // _container.Instance(_navigationService);
            // INavigationService _navigationService = IoC.Get<INavigationService>(key: "ContentFrame");
            _container.RegisterInstance(typeof(INavigationService), "ContentFrame", _navigationService);
            _navigationService.NavigateToViewModel(typeof(MainViewModel), null);
        }
示例#11
0
        public void shouldChooseDepdencyConstrurctorOverTheLongest()
        {
            SimpleContainer simpleContainer = new SimpleContainer();
            var             fs = simpleContainer.Resolve <DepedencyConstrExample>();

            simpleContainer.RegisterInstance("Ala ma kota");
            Assert.IsTrue(fs.x != null);
            Assert.IsTrue(fs.a == null);
            Assert.IsTrue(fs.b == null);
        }
示例#12
0
        [Test] // Lista 10
        public void TestRegisterInstance()
        {
            SimpleContainer c    = new SimpleContainer();
            IFoo            foo1 = new Foo();

            c.RegisterInstance <IFoo>(foo1);
            IFoo foo2 = c.Resolve <IFoo>();

            Assert.AreEqual(foo1, foo2);
        }
示例#13
0
        public void RegisterCustomClassInstance()
        {
            SimpleContainer c    = new SimpleContainer();
            IBar            bar1 = new ImplementedBar();

            c.RegisterInstance <IBar>(bar1);
            IBar bar2 = c.Resolve <IBar>();

            Assert.AreEqual(bar1, bar2);
        }
示例#14
0
        public void RegisterInstance()
        {
            SimpleContainer c = new SimpleContainer();

            c.RegisterInstance <string>("Hello world!");
            c.RegisterType <Qux>(false);
            var o1 = c.Resolve <Qux>();

            Assert.AreEqual("Hello world!", o1.GetStr());
        }
 public void RegisterSingletonAfterInstance()
 {
     SimpleContainer container = new SimpleContainer();
     ITest instance = new A();
     container.RegisterInstance<ITest>(instance);
     ITest obj1 = container.Resolve<ITest>();
     container.RegisterType<ITest>(true);
     ITest obj2 = container.Resolve<ITest>();
     Assert.AreSame(obj1, obj2);
 }
示例#16
0
        public void Container_ChooseConstructorWithRegisteredParameter()
        {
            var container = new SimpleContainer();

            container.Singleton <TwoConstructors>();
            container.RegisterInstance(typeof(int), null, 23);
            var inst = (TwoConstructors)container.GetInstance(typeof(TwoConstructors), null);

            Assert.Equal(23, inst.Value);
        }
示例#17
0
        public void RecursiveSolutionRegisterInstance()
        {
            SimpleContainer c = new SimpleContainer();
            X x;

            // Assert.Throws<Exception>(() => {x = c.Resolve<X>();} );
            c.RegisterInstance("register an instance");
            x = c.Resolve <X>();
            Assert.True(x is X);
        }
示例#18
0
        public void Container_SingleIntConstructor()
        {
            var container = new SimpleContainer();

            container.Singleton <SingleIntConstructor>();
            container.RegisterInstance(typeof(int), "x", 4);
            var inst = (SingleIntConstructor)container.GetInstance(typeof(SingleIntConstructor), null);

            Assert.Equal(4, inst.Value);
        }
示例#19
0
        public void registerInstanceTest()
        {
            SimpleContainer c   = new SimpleContainer();
            IFoo            foo = new Foo();

            c.RegisterInstance(foo);
            IFoo foo2 = c.Resolve <IFoo>();

            Assert.AreEqual(foo, foo2);
        }
示例#20
0
        public void Instance()
        {
            SimpleContainer sc = new SimpleContainer();
            IFoo            f1 = new Foo();

            sc.RegisterInstance <IFoo>(f1);
            IFoo f2 = sc.Resolve <IFoo>();

            Assert.AreEqual <IFoo>(f1, f2);
        }
        public void ResolveRegistredInstance()
        {
            // arrange
            SimpleContainer c = new SimpleContainer();

            // act
            c.RegisterInstance("ala ma kota");
            X x = c.Resolve <X>();

            // assert is handled by the ExpectedException
        }
示例#22
0
        int DoSthAndSwitch()
        {
            // set another container
            SimpleContainer c2 = new SimpleContainer();

            c2.RegisterInstance <int>(2);
            ServiceLocator.SetContainerProvider(() => c2);

            // return int from new container
            return(ServiceLocator.Current.GetInstance <int>());
        }
示例#23
0
        public void ClassWithTwoAttributedConstructors()
        {
            SimpleContainer c = new SimpleContainer();

            c.RegisterInstance <string>("abc");

            Assert.ThrowsException <ArgumentException>(() =>
            {
                ClassWithTwoAttributedConstructors a = c.Resolve <ClassWithTwoAttributedConstructors>();
            });
        }
示例#24
0
        public void shouldReturnRegisterInstance()
        {
            SimpleContainer simpleContainer = new SimpleContainer();
            IFoo            foo1            = new FooImpl();

            simpleContainer.RegisterInstance <TestProject1.IFoo>(foo1);

            IFoo foo2 = simpleContainer.Resolve <IFoo>();

            Assert.IsTrue(foo1 == foo2);
        }
示例#25
0
        public void shouldCreateWithStringInstance()
        {
            SimpleContainer simpleContainer = new SimpleContainer();

            simpleContainer.RegisterInstance("Ala ma kota");
            X x = simpleContainer.Resolve <X>();

            Assert.IsTrue(x.y != null);
            Assert.IsTrue(x.Str != null);
            Assert.IsTrue(x.Str == "Ala ma kota");
        }
示例#26
0
        public void RegisterInstance()
        {
            var c = new SimpleContainer();

            var foo1 = new ConcreteType();

            c.RegisterInstance <ITypeToResolve>(foo1);
            var foo2 = c.Resolve <ITypeToResolve>();

            Assert.AreSame(foo1, foo2);
        }
        public void BuildUpTest2()
        {
            SimpleContainer container = new SimpleContainer();
            E obj = new E();
            Z dep = new Z();

            container.RegisterInstance <Z>(dep);
            container.BuildUp <E>(obj);
            Assert.IsNotNull(obj.z);
            Assert.AreSame(dep, obj.z);
        }
示例#28
0
        public void TestRegisterInstanceReturnsSameInstance()
        {
            SimpleContainer container = new SimpleContainer();

            ClassInheritsClass object1 = new ClassInheritsClass();

            container.RegisterInstance <ClassInheritsClass>(object1);
            ClassInheritsClass object2 = container.Resolve <ClassInheritsClass>();

            Assert.AreEqual(object1, object2);
        }
示例#29
0
        protected override void Configure()
        {
            container = new SimpleContainer();

            container.Singleton <IWindowManager, WindowManager>();
            container.Singleton <IEventAggregator, EventAggregator>();

            container.Singleton <MainViewModel>();
            //container.Singleton<IUserService, UserService>();
            container.RegisterInstance(typeof(IUserService), null, new UserService());
        }
示例#30
0
        public async System.Threading.Tasks.Task InitializeAsync()
        {
            var repo = await SQLiteFarmerRepository.CreateRepository();

            _container.RegisterInstance
            (
                typeof(IFarmerRepository),
                FarmerRepositoryConstants.FarmerRepository.ToString(),
                repo
            );
        }
示例#31
0
        public void ResolveStringParameter()
        {
            const String    s1 = "ala ma kota";
            SimpleContainer c  = new SimpleContainer();

            c.RegisterInstance <string>(s1);
            X      x = c.Resolve <X>();
            String s = c.Resolve <string>();

            Assert.Equal(s1, s);
        }
示例#32
0
        public void shouldChooseTheLongestConstructor()
        {
            SimpleContainer simpleContainer = new SimpleContainer();

            simpleContainer.RegisterInstance("Ala ma kota");
            var fs = simpleContainer.Resolve <TheLongestConstrExample>();

            Assert.IsTrue(fs.x == null);
            Assert.IsTrue(fs.a != null);
            Assert.IsTrue(fs.b != null);
        }
示例#33
0
        public void ClassWithConstructorParameterCreatedBefore()
        {
            SimpleContainer c = new SimpleContainer();

            string s = "abc";

            c.RegisterInstance <string>(s);

            ClassWithStringField a = c.Resolve <ClassWithStringField>();

            Assert.AreEqual(a.s, s);
        }
        public void DealsWithDependencies()
        {
            var dependencyInstance = new Dependency();
            var container = new SimpleContainer();
            container.RegisterInstance<Dependency>(dependencyInstance);

            var policy = new TransientLifetimePolicy(typeof(Target), container);
            var instance = policy.GetInstance() as Target;

            Assert.IsNotNull(instance);
            Assert.AreEqual(dependencyInstance, instance.Dependency);
        }
示例#35
0
        protected override void Configure()
        {
            _container = new SimpleContainer();

            _container.RegisterPerRequest(typeof(ContactEditorViewModel), "ContactEditorViewModel", typeof(ContactEditorViewModel));
            _container.RegisterPerRequest(typeof(EditSensorViewModel), "EditSensorViewModel", typeof(EditSensorViewModel));
            _container.RegisterPerRequest(typeof(SpecifyValueViewModel), "SpecifyValueViewModel", typeof(SpecifyValueViewModel));
            _container.RegisterPerRequest(typeof(SensorTemplateManagerViewModel), "SensorTemplateManagerViewModel", typeof(SensorTemplateManagerViewModel));
            _container.RegisterPerRequest(typeof(ExportViewModel), "ExportViewModel", typeof(ExportViewModel));
            _container.RegisterPerRequest(typeof(SettingsViewModel), "SettingsViewModel", typeof(SettingsViewModel));
            _container.RegisterSingleton(typeof(LogWindowViewModel), "LogWindowViewModel", typeof(LogWindowViewModel));
            _container.RegisterPerRequest(typeof(ExportToImageViewModel), "ExportToImageViewModel", typeof(ExportToImageViewModel));
            _container.RegisterPerRequest(typeof(UseSelectedRangeViewModel), "UseSelectedRangeViewModel", typeof(UseSelectedRangeViewModel));
            _container.RegisterSingleton(typeof(MainWindowViewModel), "MainWindowViewModel", typeof(MainWindowViewModel));
            _container.RegisterPerRequest(typeof(EditSiteDataViewModel), "EditSiteDataViewModel", typeof(EditSiteDataViewModel));
            _container.RegisterPerRequest(typeof(MatchToExistingSensorsViewModel), "MatchToExistingSensorsViewModel", typeof(MatchToExistingSensorsViewModel));
            _container.RegisterPerRequest(typeof(CalibrationDetailsViewModel), "CalibrationDetailsViewModel", typeof(CalibrationDetailsViewModel));
            //_container.RegisterPerRequest(typeof(HeatMapViewModel), "HeatMapViewModel", typeof(HeatMapViewModel));
            _container.RegisterSingleton(typeof(AboutViewModel), "AboutViewModel", typeof(AboutViewModel));
            _container.RegisterSingleton(typeof(LoadInDataMetaViewModel), "LoadInDataMetaViewModel", typeof(LoadInDataMetaViewModel));

            _container.RegisterInstance(typeof(IWindowManager), null, new WindowManager());
            _container.RegisterInstance(typeof(SimpleContainer), null, _container);
        }
示例#36
0
        protected override void Configure()
        {
            _container = new SimpleContainer();
            IoC.Initialize(_container);

            _container.RegisterSingleton<INavigationService, FrameAdapter>();
            _container.RegisterSingleton<IEventAggregator, EventAggregator>();
            _container.RegisterSingleton<IViewModelLocator, ViewModelLocator>();
            _container.RegisterSingleton<IViewModelBinder, ViewModelBinder>();

            var typeResolver = new NameBasedViewModelTypeResolver();
            typeResolver.AddAssembly(typeof(App).GetTypeInfo().Assembly);
            _container.RegisterInstance<IViewModelTypeResolver>(typeResolver);

            _container.RegisterSingleton<MainPageViewModel>();
        }
示例#37
0
        protected override void Configure()
        {
            _container = new SimpleContainer();
            IoC.Initialize(_container);

            _container.RegisterSingleton<IWindowManager, WindowManager>();
            _container.RegisterSingleton<IEventAggregator, EventAggregator>();
            _container.RegisterSingleton<IViewModelLocator, ViewModelLocator>();
            _container.RegisterSingleton<IViewModelBinder, ViewModelBinder>();

            var typeResolver = new ViewModelTypeResolver();
            typeResolver.AddMapping<ShellView, ShellViewModel>();
            _container.RegisterInstance<IViewModelTypeResolver>(typeResolver);
            
            _container.RegisterPerRequest<ShellViewModel>();
        }