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); }
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>(); }
protected override void Configure() { container = new SimpleContainer(); container.Singleton <IWindowManager, WindowManager>(); container.RegisterInstance(typeof(IDialogService), null, new DialogService(dialogTypeLocator: new DialogTypeLocator())); container.PerRequest <MainViewModel>(); }
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); }
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(); }
public void ClassWithOneAttributedConstructor() { SimpleContainer c = new SimpleContainer(); c.RegisterInstance <string>("abc"); ClassWithOneAttributedConstructor a = c.Resolve <ClassWithOneAttributedConstructor>(); Assert.AreEqual(a.s, ""); }
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); }
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 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); }
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); }
[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); }
public void RegisterCustomClassInstance() { SimpleContainer c = new SimpleContainer(); IBar bar1 = new ImplementedBar(); c.RegisterInstance <IBar>(bar1); IBar bar2 = c.Resolve <IBar>(); Assert.AreEqual(bar1, bar2); }
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); }
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); }
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); }
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); }
public void registerInstanceTest() { SimpleContainer c = new SimpleContainer(); IFoo foo = new Foo(); c.RegisterInstance(foo); IFoo foo2 = c.Resolve <IFoo>(); Assert.AreEqual(foo, foo2); }
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 }
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>()); }
public void ClassWithTwoAttributedConstructors() { SimpleContainer c = new SimpleContainer(); c.RegisterInstance <string>("abc"); Assert.ThrowsException <ArgumentException>(() => { ClassWithTwoAttributedConstructors a = c.Resolve <ClassWithTwoAttributedConstructors>(); }); }
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); }
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"); }
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); }
public void TestRegisterInstanceReturnsSameInstance() { SimpleContainer container = new SimpleContainer(); ClassInheritsClass object1 = new ClassInheritsClass(); container.RegisterInstance <ClassInheritsClass>(object1); ClassInheritsClass object2 = container.Resolve <ClassInheritsClass>(); Assert.AreEqual(object1, object2); }
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()); }
public async System.Threading.Tasks.Task InitializeAsync() { var repo = await SQLiteFarmerRepository.CreateRepository(); _container.RegisterInstance ( typeof(IFarmerRepository), FarmerRepositoryConstants.FarmerRepository.ToString(), repo ); }
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); }
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); }
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); }
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); }
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>(); }
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>(); }