public void RegisterServicer(IServicer servicer) { if (servicer == null || string.IsNullOrEmpty(servicer.Name)) { throw new ArgumentNullException("The service or the name of service is empty"); } if (m_ServicerDic.ContainsKey(servicer.Name)) { throw new Exception($"The name of service has been added.name = {servicer.Name}."); } m_ServicerDic.Add(servicer.Name, servicer); m_OrderedByAddtionServicerNames.Add(servicer.Name); Type serviceType = servicer.GetType(); if (typeof(IUpdate).IsAssignableFrom(serviceType)) { m_UpdateServicerNames.Add(servicer.Name); } if (typeof(ILateUpdate).IsAssignableFrom(serviceType)) { m_LateUpdateServicerNames.Add(servicer.Name); } if (typeof(IFixedUpdate).IsAssignableFrom(serviceType)) { m_FixedUpdateServicerNames.Add(servicer.Name); } servicer.DoRegister(); }
public void ShouldResolveGenericDependenciesFromManuallyConstructedTypeInstances() { // Arrange Type servicerInstanceType = typeof(IServicer <>); Type recipientAType = typeof(ServiceRecipientA); Type recipientBType = typeof(ServiceRecipientB); Type servicerAType = servicerInstanceType.MakeGenericType(recipientAType); Type servicerBType = servicerInstanceType.MakeGenericType(recipientBType); // Act IServicer <ServiceRecipientA> servicerA = (BaseServiceProvider <ServiceRecipientA>)NitroxServiceLocator.LocateService(servicerAType); IServicer <ServiceRecipientB> servicerB = (BaseServiceProvider <ServiceRecipientB>)NitroxServiceLocator.LocateService(servicerBType); // Assert servicerA.Should().NotBeNull(); servicerA.Should().BeOfType <ServiceAProvider>(); Assert.ThrowsException <NotImplementedException>(() => servicerA.PerformService(null)); servicerB.Should().NotBeNull(); servicerB.Should().BeOfType <ServiceBProvider>(); Assert.ThrowsException <NotImplementedException>(() => servicerB.PerformService(null)); }
public void ShouldResolveGenericDependencies() { IServicer <ServiceRecipientA> servicerA = NitroxServiceLocator.LocateService <IServicer <ServiceRecipientA> >(); IServicer <ServiceRecipientB> servicerB = NitroxServiceLocator.LocateService <IServicer <ServiceRecipientB> >(); servicerA.Should().NotBeNull(); servicerA.Should().BeOfType <ServiceAProvider>(); servicerB.Should().NotBeNull(); servicerB.Should().BeOfType <ServiceBProvider>(); }
public void ShouldResolveGenericDependencies() { IServicer <ServiceRecipientA> servicerA = NitroxServiceLocator.LocateService <IServicer <ServiceRecipientA> >(); IServicer <ServiceRecipientB> servicerB = NitroxServiceLocator.LocateService <IServicer <ServiceRecipientB> >(); servicerA.Should().NotBeNull(); servicerA.Should().BeOfType <ServiceAProvider>(); Assert.ThrowsException <NotImplementedException>(() => servicerA.PerformService(null)); servicerB.Should().NotBeNull(); servicerB.Should().BeOfType <ServiceBProvider>(); Assert.ThrowsException <NotImplementedException>(() => servicerB.PerformService(null)); }
public virtual void RegisterServicer(IServicer servicer) { this.service.RegisterServicer(servicer); }