public void Cache_The_ImplementationType() { var manager = new ScannedTypeManager(); var type = manager.FindImplementationType(typeof(IMyAwesomeService)); Assert.AreEqual(typeof(MyAwesomeService), type); Assert.AreEqual(1, manager.ResolvedTypes.Count); Assert.AreEqual("MvvmLib.IoC.Tests.Scanned.IMyAwesomeService, MvvmLib.IoC.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", typeof(IMyAwesomeService).AssemblyQualifiedName); Assert.AreEqual(type, manager.ResolvedTypes[typeof(IMyAwesomeService).AssemblyQualifiedName]); var type2 = manager.FindImplementationType(typeof(IMyAwesomeService)); Assert.AreEqual(type2, type); }
public void Cannot_Resolve_Multiple_Implementation_WIthout_Attribute_From_Another_Assembly() { var manager = new ScannedTypeManager(); var type = manager.FindImplementationType(typeof(IMyExternalServiceC)); Assert.AreEqual(null, type); }
public void Resolve_ImplementationType_With_PreferredImplementation_Attribute_From_Another_Assembly() { var manager = new ScannedTypeManager(); var type = manager.FindImplementationType(typeof(IMyExternalServiceB)); Assert.AreEqual(typeof(MyExternalServiceB2), type); }
public void Cannot_Resolve_Multiple_Implementation_WIthout_Attribute() { var manager = new ScannedTypeManager(); var type = manager.FindImplementationType(typeof(IMyAwesomeServiceC)); Assert.AreEqual(null, type); }
public void Resolve_ImplementationType_With_PreferredImplementation_Attribute() { var manager = new ScannedTypeManager(); var type = manager.FindImplementationType(typeof(IMyAwesomeServiceB)); Assert.AreEqual(typeof(MyAwesomeServiceB2), type); }
public void Resolve_ImplementationType() { var manager = new ScannedTypeManager(); var type = manager.FindImplementationType(typeof(IMyAwesomeService)); Assert.AreEqual(typeof(MyAwesomeService), type); }
private void TryRegisterTypeIfNotRegistered(Type type, string name) { if (!IsRegistered(type, name) && autoDiscovery) { if (type.IsInterface) { var implementationType = scannedTypeManager.FindImplementationType(type); if (implementationType == null) { throw new ResolutionFailedException($"Unable to resolve the type for the interface not registered \"{type.Name}\""); } switch (lifetimeOnDiscovery) { case LifetimeOnDiscovery.Transcient: RegisterType(type, name, implementationType); break; case LifetimeOnDiscovery.SingletonOnlyForServices: RegisterType(type, name, implementationType).AsSingleton(); break; } } else { if (IsValueContainerType(type)) { throw new ResolutionFailedException($"Invalid registration type \"{type.Name}\""); } RegisterType(type, name); } } }
public void Cache_The_Assembly() { var manager = new ScannedTypeManager(); Assert.AreEqual(0, manager.Assemblies.Count); var type = manager.FindImplementationType(typeof(IMyAwesomeService)); Assert.AreEqual(1, manager.Assemblies.Count); var a1 = manager.Assemblies.First(); manager.FindImplementationType(typeof(IMyAwesomeService)); Assert.AreEqual(1, manager.Assemblies.Count); manager.FindImplementationType(typeof(IMyExternalService)); Assert.AreEqual(2, manager.Assemblies.Count); }