public void BindToExistingTypeService() { var s = new ServiceLocator(); const string name1 = "MyService1"; const string name2 = "MyService2"; // create any servie: var r = s.Register(typeof(ITestService), typeof(SimpleSiteService), ServiceMode.Singleton); // try to bind with null: s.Bind(typeof(SimpleSiteService), r); s.Bind(name1, r); s.Bind(name2, r); // get services: var o1 = s.GetService <ITestService>(); var o2 = s.GetService <ITestService>(name1); var o3 = s.GetService <ITestService>(name2); Assert.IsNotNull(r); Assert.IsNotNull(o1); Assert.IsNotNull(o2); Assert.IsNotNull(o3); Assert.AreEqual(o1, o2); Assert.AreEqual(o2, o3); }
public void Should_be_able_to_store_and_retrieve() { var instance = new Foo(); locator.Bind <IFoo>(instance); var obj = locator.Get <IFoo>(); Assert.AreSame(instance, obj); }
public void ShouldCreateTransientBindingsWithParams() { var locator = new ServiceLocator(); locator.Bind <ITestService>().ToTransient <TestService>(); locator.Bind <ITestParamsService>().ToTransient <TestParamsService>(); var service = locator.Get <ITestParamsService>(); Assert.IsNotNull(service); }
public void CreateInstanceWithBind_OverwriteBind_GivesProperInstance() { // Arrange ServiceLocator.Bind <IMultipleImplementations, ImplementationOne>(); try { // Act var instance = ServiceLocator.CreateInstance <IMultipleImplementations>(); // Assert Assert.IsType <ImplementationOne>(instance); // Rearrange ServiceLocator.Bind <IMultipleImplementations, ImplementationTwo>(); // Act instance = ServiceLocator.CreateInstance <IMultipleImplementations>(); // Assert Assert.IsType <ImplementationTwo>(instance); } finally { ServiceLocator.Unbind <IMultipleImplementations>(); } }
public void BindToNull() { var s = new ServiceLocator(); // create any servie: var r = s.Register(typeof(ITestService), typeof(SimpleSiteService), ServiceMode.Clone); // try to bind with null: s.Bind(typeof(SimpleSiteService), null); Assert.IsNull(r); }
public void Load(IServer server) { roomManager = new RoomManager(); ServiceLocator.Bind(roomManager.GetType(), roomManager); FN.Logger.Info($"RoomModule loaded"); FN.HandlerCollection.RegisterHandler(new JoinRoomHandler()); FN.HandlerCollection.RegisterHandler(new PlayerCommandHandler()); FN.Server.OnConnected += OnPeerConnected; FN.Server.OnDisconnected += OnPeerDisConnected; }
public void CreateInstanceWithBind_InterfaceHasMultipleImplementations_GivesInstance() { // Arrange ServiceLocator.Bind <IMultipleImplementations, ImplementationOne>(); try { // Act var instance = ServiceLocator.CreateInstance <IMultipleImplementations>(); // Assert Assert.IsType <ImplementationOne>(instance); } finally { ServiceLocator.Unbind <IMultipleImplementations>(); } }
public void CreateInstanceWithBindAndUnbind_InterfaceHasMultipleImplementations_Throws() { // Arrange ServiceLocator.Bind <IMultipleImplementations, ImplementationOne>(); // Act var instance = ServiceLocator.CreateInstance <IMultipleImplementations>(); // Assert Assert.IsType <ImplementationOne>(instance); // Rearrange ServiceLocator.Unbind <IMultipleImplementations>(); // Act && Assert Assert.Throws <ArgumentException>(() => ServiceLocator.CreateInstance <IMultipleImplementations>()); }
public void CrossLocatorBinding() { var s1 = new ServiceLocator(); var s2 = new ServiceLocator(); // register any service: var r1 = s1.Register(typeof(ITestService), typeof(SimpleSiteService), ServiceMode.Singleton); Assert.IsNotNull(r1); // try to bind in other locator: var r2 = s2.Bind(typeof(ITestService), r1); // since it's possible to share the same service across multiple service locators, // expect the object to be identical: Assert.IsNotNull(r2); Assert.AreEqual(r1, r2); }
public override void InstallBindings() { ServiceLocator.BindInstance(_ballLauncher); ServiceLocator.BindInstance(_brickSpawner); ServiceLocator.BindInstance(_boardController); ServiceLocator.BindInstance(_cameraController); ServiceLocator.BindInstance(_inGameScreen); ServiceLocator.BindInstance(_endScreen); ServiceLocator.Bind <GameController>(new GameController()); ServiceLocator.Bind <SimulationController>(new SimulationController()); ServiceLocator.Bind <ISimulationFinisher>(new SimulationFinishCalculator()); ServiceLocator.Bind <UiController>(new UiController()); CoroutineManager.DoAfterFixedUpdate(() => { SignalBus.Fire(new SceneReadySignal()); }); }
public void BindToExistingTypeService() { var s = new ServiceLocator(); const string name1 = "MyService1"; const string name2 = "MyService2"; // create any servie: var r = s.Register(typeof(ITestService), typeof(SimpleSiteService), ServiceMode.Singleton); // try to bind with null: s.Bind(typeof(SimpleSiteService), r); s.Bind(name1, r); s.Bind(name2, r); // get services: var o1 = s.GetService<ITestService>(); var o2 = s.GetService<ITestService>(name1); var o3 = s.GetService<ITestService>(name2); Assert.IsNotNull(r); Assert.IsNotNull(o1); Assert.IsNotNull(o2); Assert.IsNotNull(o3); Assert.AreEqual(o1, o2); Assert.AreEqual(o2, o3); }