public void WhenMultipleProvidersOfServiceExist_DefaultRegistrationIsMostRecent() { var r1 = Factory.CreateSingletonObjectRegistration(); var r2 = Factory.CreateSingletonObjectRegistration(); var registry = new ComponentRegistry(); registry.Register(r1); registry.Register(r2); IComponentRegistration defaultRegistration; Assert.True(registry.TryGetRegistration(new TypedService(typeof(object)), out defaultRegistration)); Assert.Same(r2, defaultRegistration); }
public void WhenRegistrationProvidedExplicitlyAndThroughRegistrationSource_ExplicitRegistrationIsDefault() { var r = Factory.CreateSingletonObjectRegistration(); var registry = new ComponentRegistry(); registry.Register(r); registry.AddRegistrationSource(new ObjectRegistrationSource()); IComponentRegistration defaultForObject; registry.TryGetRegistration(new TypedService(typeof(object)), out defaultForObject); Assert.AreSame(r, defaultForObject); }
public void WhenNoImplementers_TryGetRegistrationReturnsFalse() { var registry = new ComponentRegistry(); IComponentRegistration unused; Assert.IsFalse(registry.TryGetRegistration(new TypedService(typeof(object)), out unused)); }
public void WhenNoImplementerIsDirectlyRegistered_RegistrationCanBeProvidedDynamically() { var registry = new ComponentRegistry(); registry.AddRegistrationSource(new ObjectRegistrationSource()); IComponentRegistration registration; Assert.IsTrue(registry.TryGetRegistration(new TypedService(typeof(object)), out registration)); }
public void LastRegistrationSourceRegisteredIsTheDefault() { var first = new object(); var second = new object(); var registry = new ComponentRegistry(); registry.AddRegistrationSource(new ObjectRegistrationSource(first)); registry.AddRegistrationSource(new ObjectRegistrationSource(second)); IComponentRegistration def; registry.TryGetRegistration(new TypedService(typeof(object)), out def); var result = def.Activator.ActivateInstance(new ContainerBuilder().Build(), Enumerable.Empty<Parameter>()); Assert.AreEqual(result, second); }