public void GetsNames() { Assert.AreEqual("MockLogger", WithName.TypeName(typeof(MockLogger))); Assert.AreEqual("List`1", WithName.TypeName(typeof(List <>))); Assert.IsNull(WithName.Default(typeof(MockLogger))); Assert.IsNull(WithName.Default(typeof(List <>))); }
public MainWindow() { InitializeComponent(); firstUnity.RegisterInstance(typeof(IProductFactory), new ShoeProductFactory()); var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); section.Configure(secondUnity); thirdUnity.RegisterTypes( AllClasses.FromLoadedAssemblies() .Where(x => x.IsPublic && x.GetInterfaces().Any() && !x.IsAbstract && x.IsClass), WithMappings.FromAllInterfacesInSameAssembly, type => (thirdUnity.Registrations .Select(x => x.RegisteredType) .Any(r => type.GetInterfaces().Contains(r)))?WithName.TypeName(type):WithName.Default(type), WithLifetime.ContainerControlled); forthUnity.RegisterInstance(typeof(IProductFactory), new JacketProductFactory(), WithLifetime.ExternallyControlled(typeof(IProductFactory))); }
public override Func <Type, string> GetName() { return(type => unity.Registrations.Select(x => x.RegisteredType).Any(r => r.GetInterfaces().Contains(r)) ? WithName.TypeName(type) : WithName.Default(type)); }