/// <summary> /// Registers services from the given list of <paramref name="assemblies"/>. /// </summary> /// <param name="assemblies">The list of assemblies that contain the service types.</param> /// <param name="map">The dependency map.</param> private void RegisterServicesFrom(IEnumerable <Assembly> assemblies, DependencyMap map) { var serviceList = GetServiceList(assemblies); var defaultServices = GetDefaultServices(serviceList); var registeredServices = new List <IServiceInfo>(); // Apply the service filter to the list of services // that will be added to the map Predicate <IServiceInfo> nullPredicate = info => true; Predicate <IServiceInfo> filter = ServiceFilter ?? nullPredicate; foreach (var service in defaultServices) { if (!filter(service)) { continue; } registeredServices.Add(service); } foreach (var list in serviceList.Values) { foreach (var service in list) { if (!filter(service)) { continue; } registeredServices.Add(service); } } // Register the enumerable types for each service type foreach (var serviceType in serviceList.Keys) { map.AddAsEnumerableService(serviceType); } map.Register(registeredServices); }
public void ShouldBeAbleToGetAllEnumerableInstancesOfAGivenService() { var map = new DependencyMap(); map.AddService("Baz1", typeof(IBaz<int>), typeof(Baz1)); map.AddService("Baz2", typeof(IBaz<int>), typeof(Baz2)); map.AddService("Baz3", typeof(IBaz<int>), typeof(Baz3)); map.AddService(typeof(IFizz), typeof(SampleClassWithEnumerableBazDependency)); // Make the IEnumerable<IBazz<int>> service explictly resolvable map.AddAsEnumerableService(typeof(IBaz<int>)); var container = map.CreateContainer(); var fizz = container.GetInstance<IFizz>(); Assert.IsNotNull(fizz); Assert.AreEqual(3, fizz.Services.Count()); var services = fizz.Services.ToArray(); Assert.IsInstanceOfType(typeof(Baz1), services[0]); Assert.IsInstanceOfType(typeof(Baz2), services[1]); Assert.IsInstanceOfType(typeof(Baz3), services[2]); }
public void ShouldBeAbleToGetAllEnumerableInstancesOfAGivenService() { var map = new DependencyMap(); map.AddService("Baz1", typeof(IBaz <int>), typeof(Baz1)); map.AddService("Baz2", typeof(IBaz <int>), typeof(Baz2)); map.AddService("Baz3", typeof(IBaz <int>), typeof(Baz3)); map.AddService(typeof(IFizz), typeof(SampleClassWithEnumerableBazDependency)); // Make the IEnumerable<IBazz<int>> service explictly resolvable map.AddAsEnumerableService(typeof(IBaz <int>)); var container = map.CreateContainer(); var fizz = container.GetInstance <IFizz>(); Assert.IsNotNull(fizz); Assert.AreEqual(3, fizz.Services.Count()); var services = fizz.Services.ToArray(); Assert.IsInstanceOfType(typeof(Baz1), services[0]); Assert.IsInstanceOfType(typeof(Baz2), services[1]); Assert.IsInstanceOfType(typeof(Baz3), services[2]); }
/// <summary> /// Registers services from the given list of <paramref name="assemblies"/>. /// </summary> /// <param name="assemblies">The list of assemblies that contain the service types.</param> /// <param name="map">The dependency map.</param> private void RegisterServicesFrom(IEnumerable<Assembly> assemblies, DependencyMap map) { var serviceList = GetServiceList(assemblies); var defaultServices = GetDefaultServices(serviceList); var registeredServices = new List<IServiceInfo>(); // Apply the service filter to the list of services // that will be added to the map Predicate<IServiceInfo> nullPredicate = info => true; Predicate<IServiceInfo> filter = ServiceFilter ?? nullPredicate; foreach (var service in defaultServices) { if (!filter(service)) continue; registeredServices.Add(service); } foreach (var list in serviceList.Values) { foreach (var service in list) { if (!filter(service)) continue; registeredServices.Add(service); } } // Register the enumerable types for each service type foreach(var serviceType in serviceList.Keys) { map.AddAsEnumerableService(serviceType); } map.Register(registeredServices); }