From 6837496f5128931e575b1c606fa95b519d1cad35 Mon Sep 17 00:00:00 2001 From: Cristian Odea Date: Mon, 1 Dec 2014 12:49:07 +0200 Subject: [PATCH 1/7] initial version of convention based registration behavior --- .../ConventionRegistrationBehaviorTests.cs | 27 +++ .../ServiceBuilderTests.cs | 173 ++++++++++++++++++ .../ServiceEqualityComparer.cs | 20 ++ .../iQuarc.AppBoot.UnitTests.csproj | 4 + .../ConventionRegistrationBehavior.cs | 55 ++++++ .../iQuarc.AppBoot/Container/ExportBuilder.cs | 39 ++++ .../iQuarc.AppBoot/Container/IContainer.cs | 7 + .../Container/ServiceBuilder.cs | 82 +++++++++ AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj | 4 + 9 files changed, 411 insertions(+) create mode 100644 AppBoot/iQuarc.AppBoot.UnitTests/ConventionRegistrationBehaviorTests.cs create mode 100644 AppBoot/iQuarc.AppBoot.UnitTests/ServiceBuilderTests.cs create mode 100644 AppBoot/iQuarc.AppBoot.UnitTests/ServiceEqualityComparer.cs create mode 100644 AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs create mode 100644 AppBoot/iQuarc.AppBoot/Container/ExportBuilder.cs create mode 100644 AppBoot/iQuarc.AppBoot/Container/IContainer.cs create mode 100644 AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs diff --git a/AppBoot/iQuarc.AppBoot.UnitTests/ConventionRegistrationBehaviorTests.cs b/AppBoot/iQuarc.AppBoot.UnitTests/ConventionRegistrationBehaviorTests.cs new file mode 100644 index 0000000..46cb0d5 --- /dev/null +++ b/AppBoot/iQuarc.AppBoot.UnitTests/ConventionRegistrationBehaviorTests.cs @@ -0,0 +1,27 @@ +using System.Linq; +using Xunit; + +namespace iQuarc.AppBoot.UnitTests +{ + public class ConventionRegistrationBehaviorTests + { + private readonly ServiceEqualityComparer comparer = new ServiceEqualityComparer(); + + [Fact] + public void ForType_SpecificType_CreatesServiceBuilderWithSingleType() + { + ConventionRegistrationBehavior behavior = new ConventionRegistrationBehavior(); + ServiceBuilder builder = behavior.ForType(); + builder.Export(); + + ServiceInfo service = builder.GetServicesFrom(typeof(MyService)).First(); + ServiceInfo expected = new ServiceInfo(typeof(MyService), typeof(MyService), Lifetime.Instance); + + Assert.Equal(expected, service, comparer); + } + + private class MyService + { + } + } +} \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot.UnitTests/ServiceBuilderTests.cs b/AppBoot/iQuarc.AppBoot.UnitTests/ServiceBuilderTests.cs new file mode 100644 index 0000000..de01d0f --- /dev/null +++ b/AppBoot/iQuarc.AppBoot.UnitTests/ServiceBuilderTests.cs @@ -0,0 +1,173 @@ +using System.Collections.Generic; +using System.Linq; +using iQuarc.xUnitEx; +using Xunit; + +namespace iQuarc.AppBoot.UnitTests +{ + public class ServiceBuilderTests + { + private readonly ServiceEqualityComparer comparer = new ServiceEqualityComparer(); + + [Fact] + public void Export_NoExportConfiguration_RegisterServiceBuilderInContainer() + { + ServiceBuilderContainer container = new ServiceBuilderContainer(); + + ServiceBuilder builder = new ServiceBuilder(container, t => t == typeof(ServiceBuilderContainer)); + builder.Export(); + + Assert.Equal(1, container.Builders.Count); + } + + + [Fact] + public void Export_NoExportConfiguration_RegisterService() + { + ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(ServiceBuilderContainer)); + builder.Export(); + + List services = builder.GetServicesFrom(typeof(ServiceBuilderContainer)).ToList(); + Assert.Equal(1, services.Count); + } + + [Fact] + public void Export_NoExportConfiguration_RegisterSameTypeAsContract() + { + ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(ServiceBuilderContainer)); + builder.Export(); + + ServiceInfo service = builder.GetServicesFrom(typeof(ServiceBuilderContainer)).First(); + + ServiceInfo expected = new ServiceInfo(typeof(ServiceBuilderContainer), typeof(ServiceBuilderContainer), Lifetime.Instance); + + Assert.Equal(expected, service, comparer); + } + + [Fact] + public void Export_ConfigureContractType_RegisterContractType() + { + ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(ServiceBuilderContainer)); + builder.Export(c => c.AsContractType>()); + + ServiceInfo service = builder.GetServicesFrom(typeof(ServiceBuilderContainer)).First(); + + ServiceInfo expected = new ServiceInfo(typeof(ServiceBuilderContainer), typeof(IContainer), Lifetime.Instance); + + Assert.Equal(expected, service, comparer); + } + + [Fact] + public void Export_ConfigureContractName_RegisterContractName() + { + ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(ServiceBuilderContainer)); + builder.Export(c => c.AsContractName("MyContract")); + + ServiceInfo service = builder.GetServicesFrom(typeof(ServiceBuilderContainer)).First(); + + ServiceInfo expected = new ServiceInfo(typeof(ServiceBuilderContainer), typeof(ServiceBuilderContainer), "MyContract", Lifetime.Instance); + + Assert.Equal(expected, service, comparer); + } + + [Fact] + public void Export_ConfigureLifetime_RegisterLifetime() + { + ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(ServiceBuilderContainer)); + builder.Export(c => c.WithLifetime(Lifetime.Application)); + + ServiceInfo service = builder.GetServicesFrom(typeof(ServiceBuilderContainer)).First(); + + ServiceInfo expected = new ServiceInfo(typeof(ServiceBuilderContainer), typeof(ServiceBuilderContainer), Lifetime.Application); + + Assert.Equal(expected, service, comparer); + } + + [Fact] + public void Export_ExportInterfacesSingleInterface_RegisterContractType() + { + ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(ServiceBuilderContainer)); + builder.ExportInterfaces(); + + ServiceInfo service = builder.GetServicesFrom(typeof(ServiceBuilderContainer)).First(); + + ServiceInfo expected = new ServiceInfo(typeof(ServiceBuilderContainer), typeof(IContainer), Lifetime.Instance); + + Assert.Equal(expected, service, comparer); + } + + [Fact] + public void Export_ExportInterfacesMultipleInterfaces_RegisterMultipleContractTypes() + { + ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(MyService)); + builder.ExportInterfaces(); + + List services = builder.GetServicesFrom(typeof(MyService)).ToList(); + + List expected = new List + { + new ServiceInfo(typeof (MyService), typeof (IMyService1), Lifetime.Instance), + new ServiceInfo(typeof (MyService), typeof (IMyService2), Lifetime.Instance), + }; + + AssertEx.AreEquivalent(services, (x, y) => comparer.Equals(x, y), expected[0], expected[1]); + } + + [Fact] + public void Export_ExportInterfacesWithFilter_RegisterContractType() + { + ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(MyService)); + builder.ExportInterfaces(x => x == typeof(IMyService2)); + + List services = builder.GetServicesFrom(typeof(MyService)).ToList(); + + ServiceInfo expected = new ServiceInfo(typeof (MyService), typeof (IMyService2), Lifetime.Instance); + + AssertEx.AreEquivalent(services, (x, y) => comparer.Equals(x, y), expected); + } + + [Fact] + public void Export_ExportInterfacesMultipleInterfacesWithExportConfig_RegisterConfig() + { + ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(MyService)); + builder.ExportInterfaces(c => true, b => b.WithLifetime(Lifetime.Application)); + + List services = builder.GetServicesFrom(typeof(MyService)).ToList(); + + List expected = new List + { + new ServiceInfo(typeof (MyService), typeof (IMyService1), Lifetime.Application), + new ServiceInfo(typeof (MyService), typeof (IMyService2), Lifetime.Application), + }; + + AssertEx.AreEquivalent(services, (x, y) => comparer.Equals(x, y), expected[0], expected[1]); + } + + private class ServiceBuilderContainer : IContainer + { + public ServiceBuilderContainer() + { + this.Builders = new List(); + } + + public IList Builders { get; set; } + + public void Register(ServiceBuilder item) + { + Builders.Add(item); + } + } + + private class MyService : IMyService1, IMyService2 + { + } + + internal interface IMyService1 + { + } + + internal interface IMyService2 + { + } + } +} diff --git a/AppBoot/iQuarc.AppBoot.UnitTests/ServiceEqualityComparer.cs b/AppBoot/iQuarc.AppBoot.UnitTests/ServiceEqualityComparer.cs new file mode 100644 index 0000000..d6a0f14 --- /dev/null +++ b/AppBoot/iQuarc.AppBoot.UnitTests/ServiceEqualityComparer.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace iQuarc.AppBoot.UnitTests +{ + internal class ServiceEqualityComparer : IEqualityComparer + { + public bool Equals(ServiceInfo x, ServiceInfo y) + { + return x.ContractName == y.ContractName && + x.From == y.From && + x.To == y.To && + x.InstanceLifetime == y.InstanceLifetime; + } + + public int GetHashCode(ServiceInfo obj) + { + return obj.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot.UnitTests/iQuarc.AppBoot.UnitTests.csproj b/AppBoot/iQuarc.AppBoot.UnitTests/iQuarc.AppBoot.UnitTests.csproj index cf2bdc5..e0ee278 100644 --- a/AppBoot/iQuarc.AppBoot.UnitTests/iQuarc.AppBoot.UnitTests.csproj +++ b/AppBoot/iQuarc.AppBoot.UnitTests/iQuarc.AppBoot.UnitTests.csproj @@ -45,6 +45,7 @@ ..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll + ..\packages\Moq.4.2.1312.1622\lib\net40\Moq.dll @@ -63,10 +64,13 @@ + + + diff --git a/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs b/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs new file mode 100644 index 0000000..669ae68 --- /dev/null +++ b/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace iQuarc.AppBoot +{ + public class ConventionRegistrationBehavior : IRegistrationBehavior, IContainer + { + private readonly IList builders = new List(); + + public IEnumerable GetServicesFrom(Type type) + { + IEnumerable services = builders.SelectMany(x => x.GetServicesFrom(type)); + return services; + } + + public ServiceBuilder ForType(Type type) + { + ServiceBuilder builder = CreateServiceBuilder(x => x == type); + return builder; + } + + public ServiceBuilder ForType() + { + return this.ForType(typeof (T)); + } + + public ServiceBuilder ForTypesDerivedFrom(Type type) + { + ServiceBuilder builder = CreateServiceBuilder(x => type.IsAssignableFrom(x)); + return builder; + } + + public ServiceBuilder ForTypesDerivedFrom() + { + return ForTypesDerivedFrom(typeof (T)); + } + + public ServiceBuilder ForTypesMatching(Predicate typeFilter) + { + ServiceBuilder builder = CreateServiceBuilder(typeFilter); + return builder; + } + + void IContainer.Register(ServiceBuilder builder) + { + this.builders.Add(builder); + } + + private ServiceBuilder CreateServiceBuilder(Predicate typeFilter) + { + return new ServiceBuilder(this, typeFilter); + } + } +} \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot/Container/ExportBuilder.cs b/AppBoot/iQuarc.AppBoot/Container/ExportBuilder.cs new file mode 100644 index 0000000..3b8fb11 --- /dev/null +++ b/AppBoot/iQuarc.AppBoot/Container/ExportBuilder.cs @@ -0,0 +1,39 @@ +using System; + +namespace iQuarc.AppBoot +{ + public class ExportBuilder + { + private Type contractType; + private string contractName; + private Lifetime life = Lifetime.Instance; + + public ExportBuilder AsContractName(string name) + { + this.contractName = name; + return this; + } + + public ExportBuilder AsContractType(Type type) + { + this.contractType = type; + return this; + } + + public ExportBuilder AsContractType() + { + return AsContractType(typeof (T)); + } + + public ExportBuilder WithLifetime(Lifetime lifetime) + { + this.life = lifetime; + return this; + } + + internal ServiceInfo GetServiceInfo(Type type) + { + return new ServiceInfo(type, contractType ?? type, contractName, life); + } + } +} \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot/Container/IContainer.cs b/AppBoot/iQuarc.AppBoot/Container/IContainer.cs new file mode 100644 index 0000000..a16a8f9 --- /dev/null +++ b/AppBoot/iQuarc.AppBoot/Container/IContainer.cs @@ -0,0 +1,7 @@ +namespace iQuarc.AppBoot +{ + public interface IContainer + { + void Register(T item); + } +} \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs b/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs new file mode 100644 index 0000000..b2025ba --- /dev/null +++ b/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace iQuarc.AppBoot +{ + public class ServiceBuilder + { + private readonly IContainer container; + private readonly Predicate filter; + private readonly IList configs = new List(); + + internal ServiceBuilder(IContainer container, Predicate filter) + { + this.container = container; + this.filter = filter; + } + + public void Export() + { + this.Export(c => {}); + } + + public void Export(Action exportConfiguration) + { + configs.Add(new ExportConfig { ContractsProvider = t => new[] { t }, ExportConfiguration = exportConfiguration }); + container.Register(this); + } + + public void ExportInterfaces() + { + this.ExportInterfaces(x => true); + } + + public void ExportInterfaces(Predicate interfaceFilter) + { + this.ExportInterfaces(interfaceFilter, c => {}); + } + + public void ExportInterfaces(Predicate interfaceFilter, Action exportConfiguration) + { + Func> interfaces = t => t.GetInterfaces().Where(x => interfaceFilter(x)); + + configs.Add(new ExportConfig { ExportConfiguration = exportConfiguration, ContractsProvider = interfaces }); + container.Register(this); + } + + internal IEnumerable GetServicesFrom(Type type) + { + bool isMatch = filter(type); + if (!isMatch) + yield break; + + foreach (ExportConfig config in configs) + { + IEnumerable contracts = config.ContractsProvider(type); + + foreach (Type contract in contracts) + { + ExportBuilder builder = new ExportBuilder(); + builder.AsContractType(contract); + + config.ExportConfiguration(builder); + + yield return builder.GetServiceInfo(type); + } + } + } + + internal void RegisterConfig(ExportConfig config) + { + this.configs.Add(config); + } + + internal class ExportConfig + { + internal Action ExportConfiguration { get; set; } + + internal Func> ContractsProvider { get; set; } + } + } +} \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj b/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj index d1caaba..0f02621 100644 --- a/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj +++ b/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj @@ -57,7 +57,11 @@ + + + + From 9f932f319af5e8c0d80743bea06e7d04956c1c19 Mon Sep 17 00:00:00 2001 From: Florin Date: Tue, 2 Dec 2014 15:01:06 +0200 Subject: [PATCH 2/7] review convention registration design and unit tests --- .../ConventionRegistrationBehaviorTests.cs | 133 ++++++++++++++--- .../ServiceBuilderTests.cs | 137 +++++++++--------- .../ConventionRegistrationBehavior.cs | 20 ++- .../iQuarc.AppBoot/Container/IContainer.cs | 4 +- .../Container/ServiceBuilder.cs | 20 +-- 5 files changed, 213 insertions(+), 101 deletions(-) diff --git a/AppBoot/iQuarc.AppBoot.UnitTests/ConventionRegistrationBehaviorTests.cs b/AppBoot/iQuarc.AppBoot.UnitTests/ConventionRegistrationBehaviorTests.cs index 46cb0d5..cc6f396 100644 --- a/AppBoot/iQuarc.AppBoot.UnitTests/ConventionRegistrationBehaviorTests.cs +++ b/AppBoot/iQuarc.AppBoot.UnitTests/ConventionRegistrationBehaviorTests.cs @@ -1,27 +1,118 @@ using System.Linq; +using iQuarc.xUnitEx; using Xunit; namespace iQuarc.AppBoot.UnitTests { - public class ConventionRegistrationBehaviorTests - { - private readonly ServiceEqualityComparer comparer = new ServiceEqualityComparer(); - - [Fact] - public void ForType_SpecificType_CreatesServiceBuilderWithSingleType() - { - ConventionRegistrationBehavior behavior = new ConventionRegistrationBehavior(); - ServiceBuilder builder = behavior.ForType(); - builder.Export(); - - ServiceInfo service = builder.GetServicesFrom(typeof(MyService)).First(); - ServiceInfo expected = new ServiceInfo(typeof(MyService), typeof(MyService), Lifetime.Instance); - - Assert.Equal(expected, service, comparer); - } - - private class MyService - { - } - } + public class ConventionRegistrationBehaviorTests + { + private readonly ServiceEqualityComparer comparer = new ServiceEqualityComparer(); + + [Fact] + public void GetServicesFrom_TwoConventionsForType_BothExported() + { + ConventionRegistrationBehavior conventions = GetTarget(); + conventions.ForType().Export(b => b.AsContractName("Configuration 1")); + conventions.ForType().Export(b => b.AsContractName("Configuration 2")); + + conventions.GetServicesFrom(typeof (MyService)); + + var services = conventions.GetServicesFrom(typeof (MyService)); + + ServiceInfo[] expected = + { + new ServiceInfo(typeof (MyService), typeof (MyService), "Configuration 1", Lifetime.Instance), + new ServiceInfo(typeof (MyService), typeof (MyService), "Configuration 2", Lifetime.Instance) + }; + AssertEx.AreEquivalent(services, comparer.Equals, expected); + } + + [Fact] + public void GetServicesFrom_NoConventions_NothingExported() + { + ConventionRegistrationBehavior conventions = GetTarget(); + + conventions.GetServicesFrom(typeof (MyService)); + + ServiceInfo[] services = conventions.GetServicesFrom(typeof (MyService)).ToArray(); + Assert.Equal(0, services.Length); + } + + [Fact] + public void ForType_ConfigurationForMatchingType_OneMatches() + { + ConventionRegistrationBehavior behavior = GetTarget(); + + ServiceBuilder serviceBuilder = behavior.ForType(); + + Assert.True(serviceBuilder.IsMatch(typeof (MyService))); + } + + [Fact] + public void ForType_ConfigurationForNonMatchingType_MatchIsFalse() + { + ConventionRegistrationBehavior behavior = GetTarget(); + + ServiceBuilder serviceBuilder = behavior.ForType(); + + Assert.False(serviceBuilder.IsMatch(typeof (MyOtherService))); + } + + [Fact] + public void ForType_OneConfiguration_BehaviorContainsCreatedBuilder() + { + ConventionRegistrationBehavior behavior = GetTarget(); + + ServiceBuilder serviceBuilder = behavior.ForType(); + + Assert.Contains(serviceBuilder, behavior); + } + + [Fact] + public void ForTypesDerivedFrom_ConfigurationWithBaseAndInheritedTypes_MatchIsTrue() + { + ConventionRegistrationBehavior behavior = GetTarget(); + + ServiceBuilder serviceBuilder = behavior.ForTypesDerivedFrom(); + + Assert.True(serviceBuilder.IsMatch(typeof (MyService))); + } + + [Fact] + public void ForTypesDerivedFrom_ConfigurationUnrelatedTypes_MatchIsFalse() + { + ConventionRegistrationBehavior behavior = GetTarget(); + + ServiceBuilder serviceBuilder = behavior.ForTypesDerivedFrom(); + + Assert.False(serviceBuilder.IsMatch(typeof (MyOtherService))); + } + + [Fact] + public void ForTypesDerivedFrom_OneConfiguration_BehaviorContainsCreatedBuilder() + { + ConventionRegistrationBehavior behavior = GetTarget(); + + ServiceBuilder serviceBuilder = behavior.ForTypesDerivedFrom(); + + Assert.Contains(serviceBuilder, behavior); + } + + private class MyService : MyBaseService + { + } + + private class MyOtherService + { + } + + private class MyBaseService + { + } + + private static ConventionRegistrationBehavior GetTarget() + { + return new ConventionRegistrationBehavior(); + } + } } \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot.UnitTests/ServiceBuilderTests.cs b/AppBoot/iQuarc.AppBoot.UnitTests/ServiceBuilderTests.cs index de01d0f..b9855e3 100644 --- a/AppBoot/iQuarc.AppBoot.UnitTests/ServiceBuilderTests.cs +++ b/AppBoot/iQuarc.AppBoot.UnitTests/ServiceBuilderTests.cs @@ -10,153 +10,155 @@ public class ServiceBuilderTests private readonly ServiceEqualityComparer comparer = new ServiceEqualityComparer(); [Fact] - public void Export_NoExportConfiguration_RegisterServiceBuilderInContainer() + public void GetServicesFrom_NoExportConfiguration_RegisterService() { - ServiceBuilderContainer container = new ServiceBuilderContainer(); - - ServiceBuilder builder = new ServiceBuilder(container, t => t == typeof(ServiceBuilderContainer)); + ServiceBuilder builder = new ServiceBuilder(t => t == typeof(MyService)); builder.Export(); - Assert.Equal(1, container.Builders.Count); - } - - - [Fact] - public void Export_NoExportConfiguration_RegisterService() - { - ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(ServiceBuilderContainer)); - builder.Export(); - - List services = builder.GetServicesFrom(typeof(ServiceBuilderContainer)).ToList(); + List services = builder.GetServicesFrom(typeof(MyService)).ToList(); Assert.Equal(1, services.Count); } [Fact] - public void Export_NoExportConfiguration_RegisterSameTypeAsContract() + public void GetServicesFrom_NoExportConfiguration_RegisterSameTypeAsContract() { - ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(ServiceBuilderContainer)); + ServiceBuilder builder = new ServiceBuilder(t => t == typeof(MyService)); builder.Export(); - ServiceInfo service = builder.GetServicesFrom(typeof(ServiceBuilderContainer)).First(); + ServiceInfo service = builder.GetServicesFrom(typeof(MyService)).First(); - ServiceInfo expected = new ServiceInfo(typeof(ServiceBuilderContainer), typeof(ServiceBuilderContainer), Lifetime.Instance); + ServiceInfo expected = new ServiceInfo(typeof(MyService), typeof(MyService), Lifetime.Instance); Assert.Equal(expected, service, comparer); } [Fact] - public void Export_ConfigureContractType_RegisterContractType() + public void GetServicesFrom_ConfigureContractType_RegisterContractType() { - ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(ServiceBuilderContainer)); - builder.Export(c => c.AsContractType>()); + ServiceBuilder builder = new ServiceBuilder(t => t == typeof(MyService)); + builder.Export(c => c.AsContractType()); - ServiceInfo service = builder.GetServicesFrom(typeof(ServiceBuilderContainer)).First(); + ServiceInfo service = builder.GetServicesFrom(typeof(MyService)).First(); - ServiceInfo expected = new ServiceInfo(typeof(ServiceBuilderContainer), typeof(IContainer), Lifetime.Instance); + ServiceInfo expected = new ServiceInfo(typeof(MyService), typeof(IMyService1), Lifetime.Instance); Assert.Equal(expected, service, comparer); } [Fact] - public void Export_ConfigureContractName_RegisterContractName() + public void GetServicesFrom_ConfigureContractName_RegisterContractName() { - ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(ServiceBuilderContainer)); + ServiceBuilder builder = new ServiceBuilder(t => t == typeof(MyService)); builder.Export(c => c.AsContractName("MyContract")); - ServiceInfo service = builder.GetServicesFrom(typeof(ServiceBuilderContainer)).First(); + ServiceInfo service = builder.GetServicesFrom(typeof(MyService)).First(); - ServiceInfo expected = new ServiceInfo(typeof(ServiceBuilderContainer), typeof(ServiceBuilderContainer), "MyContract", Lifetime.Instance); + ServiceInfo expected = new ServiceInfo(typeof(MyService), typeof(MyService), "MyContract", Lifetime.Instance); Assert.Equal(expected, service, comparer); } [Fact] - public void Export_ConfigureLifetime_RegisterLifetime() + public void GetServicesFrom_ConfigureLifetime_RegisterLifetime() { - ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(ServiceBuilderContainer)); + ServiceBuilder builder = new ServiceBuilder(t => t == typeof(MyService)); builder.Export(c => c.WithLifetime(Lifetime.Application)); - ServiceInfo service = builder.GetServicesFrom(typeof(ServiceBuilderContainer)).First(); + ServiceInfo service = builder.GetServicesFrom(typeof(MyService)).First(); - ServiceInfo expected = new ServiceInfo(typeof(ServiceBuilderContainer), typeof(ServiceBuilderContainer), Lifetime.Application); + ServiceInfo expected = new ServiceInfo(typeof(MyService), typeof(MyService), Lifetime.Application); Assert.Equal(expected, service, comparer); } - [Fact] - public void Export_ExportInterfacesSingleInterface_RegisterContractType() - { - ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(ServiceBuilderContainer)); - builder.ExportInterfaces(); + [Fact] + public void GetServicesFrom_ExportInterfacesNoInterfaces_NothingRegistered() + { + ServiceBuilder builder = new ServiceBuilder(t => t == typeof (MyOtherService)); + builder.ExportInterfaces(); - ServiceInfo service = builder.GetServicesFrom(typeof(ServiceBuilderContainer)).First(); + ServiceInfo[] service = builder.GetServicesFrom(typeof (MyOtherService)).ToArray(); - ServiceInfo expected = new ServiceInfo(typeof(ServiceBuilderContainer), typeof(IContainer), Lifetime.Instance); + Assert.Equal(0, service.Length); + } - Assert.Equal(expected, service, comparer); - } - - [Fact] - public void Export_ExportInterfacesMultipleInterfaces_RegisterMultipleContractTypes() + [Fact] + public void GetServicesFrom_ExportInterfacesMultipleInterfaces_RegisterMultipleContractTypes() { - ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(MyService)); + ServiceBuilder builder = new ServiceBuilder(t => t == typeof(MyService)); builder.ExportInterfaces(); List services = builder.GetServicesFrom(typeof(MyService)).ToList(); - List expected = new List + ServiceInfo[] expected = { new ServiceInfo(typeof (MyService), typeof (IMyService1), Lifetime.Instance), new ServiceInfo(typeof (MyService), typeof (IMyService2), Lifetime.Instance), }; - AssertEx.AreEquivalent(services, (x, y) => comparer.Equals(x, y), expected[0], expected[1]); + AssertEx.AreEquivalent(services, comparer.Equals, expected); } [Fact] - public void Export_ExportInterfacesWithFilter_RegisterContractType() + public void GetServicesFrom_ExportInterfacesWithFilter_RegisterContractType() { - ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(MyService)); + ServiceBuilder builder = new ServiceBuilder(t => t == typeof(MyService)); builder.ExportInterfaces(x => x == typeof(IMyService2)); List services = builder.GetServicesFrom(typeof(MyService)).ToList(); ServiceInfo expected = new ServiceInfo(typeof (MyService), typeof (IMyService2), Lifetime.Instance); - AssertEx.AreEquivalent(services, (x, y) => comparer.Equals(x, y), expected); + AssertEx.AreEquivalent(services, comparer.Equals, expected); } [Fact] - public void Export_ExportInterfacesMultipleInterfacesWithExportConfig_RegisterConfig() + public void GetServicesFrom_ExportInterfacesMultipleInterfacesWithExportConfig_RegisterConfig() { - ServiceBuilder builder = new ServiceBuilder(new ServiceBuilderContainer(), t => t == typeof(MyService)); + ServiceBuilder builder = new ServiceBuilder(t => t == typeof(MyService)); builder.ExportInterfaces(c => true, b => b.WithLifetime(Lifetime.Application)); List services = builder.GetServicesFrom(typeof(MyService)).ToList(); - List expected = new List + ServiceInfo[] expected = { new ServiceInfo(typeof (MyService), typeof (IMyService1), Lifetime.Application), new ServiceInfo(typeof (MyService), typeof (IMyService2), Lifetime.Application), }; - AssertEx.AreEquivalent(services, (x, y) => comparer.Equals(x, y), expected[0], expected[1]); + AssertEx.AreEquivalent(services, comparer.Equals, expected); } - private class ServiceBuilderContainer : IContainer - { - public ServiceBuilderContainer() - { - this.Builders = new List(); - } + [Fact] + public void GetServicesFrom_MultipleConfigurations_AllConfigurationsExported() + { + ServiceBuilder builder = new ServiceBuilder(t => t == typeof(MyService)); + builder.Export(c => c.AsContractType()); + builder.Export(c => c.AsContractType()); - public IList Builders { get; set; } + var services = builder.GetServicesFrom(typeof(MyService)); - public void Register(ServiceBuilder item) - { - Builders.Add(item); - } - } + + ServiceInfo[] expected = new[] + { + new ServiceInfo(typeof (MyService), typeof (IMyService1), Lifetime.Instance), + new ServiceInfo(typeof (MyService), typeof (IMyService2), Lifetime.Instance), + }; + AssertEx.AreEquivalent(services, comparer.Equals, expected); + } + + [Fact] + public void GetServicesFrom_ExportBuilderWithMultipleConfigs_AllConfigurationsExported() + { + ServiceBuilder builder = new ServiceBuilder(t => t == typeof (MyService)); + builder.Export(c => c.AsContractType().AsContractName("IMyService1").WithLifetime(Lifetime.Application)); + + var services = builder.GetServicesFrom(typeof (MyService)); + + + ServiceInfo[] expected = {new ServiceInfo(typeof (MyService), typeof (IMyService1), "IMyService1", Lifetime.Application)}; + AssertEx.AreEquivalent(services, comparer.Equals, expected); + } private class MyService : IMyService1, IMyService2 { @@ -169,5 +171,8 @@ internal interface IMyService1 internal interface IMyService2 { } + + private class MyOtherService + { } } } diff --git a/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs b/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs index 669ae68..7846bb4 100644 --- a/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs +++ b/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; @@ -17,7 +18,8 @@ public IEnumerable GetServicesFrom(Type type) public ServiceBuilder ForType(Type type) { ServiceBuilder builder = CreateServiceBuilder(x => x == type); - return builder; + builders.Add(builder); + return builder; } public ServiceBuilder ForType() @@ -28,7 +30,8 @@ public ServiceBuilder ForType() public ServiceBuilder ForTypesDerivedFrom(Type type) { ServiceBuilder builder = CreateServiceBuilder(x => type.IsAssignableFrom(x)); - return builder; + builders.Add(builder); + return builder; } public ServiceBuilder ForTypesDerivedFrom() @@ -39,6 +42,7 @@ public ServiceBuilder ForTypesDerivedFrom() public ServiceBuilder ForTypesMatching(Predicate typeFilter) { ServiceBuilder builder = CreateServiceBuilder(typeFilter); + builders.Add(builder); return builder; } @@ -49,7 +53,17 @@ void IContainer.Register(ServiceBuilder builder) private ServiceBuilder CreateServiceBuilder(Predicate typeFilter) { - return new ServiceBuilder(this, typeFilter); + return new ServiceBuilder(typeFilter); } + + public IEnumerator GetEnumerator() + { + return builders.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } } } \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot/Container/IContainer.cs b/AppBoot/iQuarc.AppBoot/Container/IContainer.cs index a16a8f9..6836dd9 100644 --- a/AppBoot/iQuarc.AppBoot/Container/IContainer.cs +++ b/AppBoot/iQuarc.AppBoot/Container/IContainer.cs @@ -1,6 +1,8 @@ +using System.Collections.Generic; + namespace iQuarc.AppBoot { - public interface IContainer + public interface IContainer : IEnumerable { void Register(T item); } diff --git a/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs b/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs index b2025ba..d56387e 100644 --- a/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs +++ b/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs @@ -6,13 +6,11 @@ namespace iQuarc.AppBoot { public class ServiceBuilder { - private readonly IContainer container; private readonly Predicate filter; private readonly IList configs = new List(); - internal ServiceBuilder(IContainer container, Predicate filter) + internal ServiceBuilder(Predicate filter) { - this.container = container; this.filter = filter; } @@ -24,7 +22,6 @@ public void Export() public void Export(Action exportConfiguration) { configs.Add(new ExportConfig { ContractsProvider = t => new[] { t }, ExportConfiguration = exportConfiguration }); - container.Register(this); } public void ExportInterfaces() @@ -42,13 +39,16 @@ public void ExportInterfaces(Predicate interfaceFilter, Action> interfaces = t => t.GetInterfaces().Where(x => interfaceFilter(x)); configs.Add(new ExportConfig { ExportConfiguration = exportConfiguration, ContractsProvider = interfaces }); - container.Register(this); } - internal IEnumerable GetServicesFrom(Type type) + public bool IsMatch(Type type) + { + return filter(type); + } + + internal IEnumerable GetServicesFrom(Type type) { - bool isMatch = filter(type); - if (!isMatch) + if (!IsMatch(type)) yield break; foreach (ExportConfig config in configs) @@ -67,12 +67,12 @@ internal IEnumerable GetServicesFrom(Type type) } } - internal void RegisterConfig(ExportConfig config) + internal void RegisterConfig(ExportConfig config) { this.configs.Add(config); } - internal class ExportConfig + internal class ExportConfig { internal Action ExportConfiguration { get; set; } From ed700a33dfb91015484f022eaea3e1b2c2706df6 Mon Sep 17 00:00:00 2001 From: Cristian Odea Date: Tue, 2 Dec 2014 18:21:33 +0200 Subject: [PATCH 3/7] added more unit tests and removed unnecessary code --- .../BootstrapperTests.cs | 16 ++++++-- .../ConventionRegistrationBehaviorTests.cs | 38 ++++++++++--------- .../ServiceBuilderTests.cs | 11 ++++++ .../ServiceRegistrationBehaviorTests.cs | 8 ---- .../ConventionRegistrationBehavior.cs | 21 ++-------- .../iQuarc.AppBoot/Container/IContainer.cs | 9 ----- .../Container/ServiceBuilder.cs | 4 +- AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj | 1 - 8 files changed, 49 insertions(+), 59 deletions(-) delete mode 100644 AppBoot/iQuarc.AppBoot/Container/IContainer.cs diff --git a/AppBoot/iQuarc.AppBoot.UnitTests/BootstrapperTests.cs b/AppBoot/iQuarc.AppBoot.UnitTests/BootstrapperTests.cs index cf7d887..1cb3549 100644 --- a/AppBoot/iQuarc.AppBoot.UnitTests/BootstrapperTests.cs +++ b/AppBoot/iQuarc.AppBoot.UnitTests/BootstrapperTests.cs @@ -43,6 +43,7 @@ public void Run_RegistrationBehaviorReturnsOneService_TypeRegistered() IRegistrationBehavior regBehaviorStub = GetRegBehaviorStub(testSi); Mock containerMock = GetFakeContainer(); + Bootstrapper bootstrapper = GetTargetWithAssembly(containerMock); bootstrapper.AddRegistrationBehavior(regBehaviorStub); @@ -51,12 +52,16 @@ public void Run_RegistrationBehaviorReturnsOneService_TypeRegistered() containerMock.Verify(c => c.RegisterService(testSi), Times.AtLeastOnce); } - private Bootstrapper GetTargetWithAssemblyAndFakeContainer() + [Fact] + public void Dispose_DisposableDependencyContainer_DisposesContainer() { - Assembly[] assemblies = {typeof (BootstrapperTests).Assembly}; - IDependencyContainer container = GetFakeContainer().Object; + Mock containerMock = GetFakeContainer(); + Mock disposable = containerMock.As(); - return new Bootstrapper(assemblies, container); + Bootstrapper bootstrapper = GetTargetWithAssembly(containerMock); + + bootstrapper.Dispose(); + disposable.Verify(c => c.Dispose(), Times.Once); } private static Bootstrapper GetTarget(Mock fakeContainer) @@ -91,6 +96,9 @@ private static Mock GetFakeContainer(IServiceLocator servi Mock containerStub = new Mock(); containerStub.Setup(c => c.AsServiceLocator).Returns(serviceLocator); + + containerStub.As(); + return containerStub; } diff --git a/AppBoot/iQuarc.AppBoot.UnitTests/ConventionRegistrationBehaviorTests.cs b/AppBoot/iQuarc.AppBoot.UnitTests/ConventionRegistrationBehaviorTests.cs index cc6f396..6f4b472 100644 --- a/AppBoot/iQuarc.AppBoot.UnitTests/ConventionRegistrationBehaviorTests.cs +++ b/AppBoot/iQuarc.AppBoot.UnitTests/ConventionRegistrationBehaviorTests.cs @@ -58,16 +58,6 @@ public void ForType_ConfigurationForNonMatchingType_MatchIsFalse() Assert.False(serviceBuilder.IsMatch(typeof (MyOtherService))); } - [Fact] - public void ForType_OneConfiguration_BehaviorContainsCreatedBuilder() - { - ConventionRegistrationBehavior behavior = GetTarget(); - - ServiceBuilder serviceBuilder = behavior.ForType(); - - Assert.Contains(serviceBuilder, behavior); - } - [Fact] public void ForTypesDerivedFrom_ConfigurationWithBaseAndInheritedTypes_MatchIsTrue() { @@ -88,15 +78,25 @@ public void ForTypesDerivedFrom_ConfigurationUnrelatedTypes_MatchIsFalse() Assert.False(serviceBuilder.IsMatch(typeof (MyOtherService))); } - [Fact] - public void ForTypesDerivedFrom_OneConfiguration_BehaviorContainsCreatedBuilder() - { - ConventionRegistrationBehavior behavior = GetTarget(); + [Fact] + public void ForTypesMatching_ConfigurationWithServiceSuffix_MatchIsTrue() + { + ConventionRegistrationBehavior behavior = GetTarget(); - ServiceBuilder serviceBuilder = behavior.ForTypesDerivedFrom(); + ServiceBuilder serviceBuilder = behavior.ForTypesMatching(t => t.Name.EndsWith("Service")); - Assert.Contains(serviceBuilder, behavior); - } + Assert.True(serviceBuilder.IsMatch(typeof(MyService))); + } + + [Fact] + public void ForTypesMatching_ConfigurationWithNoServiceSuffix_MatchIsFalse() + { + ConventionRegistrationBehavior behavior = GetTarget(); + + ServiceBuilder serviceBuilder = behavior.ForTypesMatching(t => t.Name.EndsWith("Service")); + + Assert.False(serviceBuilder.IsMatch(typeof(Repository))); + } private class MyService : MyBaseService { @@ -110,6 +110,10 @@ private class MyBaseService { } + private class Repository + { + } + private static ConventionRegistrationBehavior GetTarget() { return new ConventionRegistrationBehavior(); diff --git a/AppBoot/iQuarc.AppBoot.UnitTests/ServiceBuilderTests.cs b/AppBoot/iQuarc.AppBoot.UnitTests/ServiceBuilderTests.cs index b9855e3..bb5bf60 100644 --- a/AppBoot/iQuarc.AppBoot.UnitTests/ServiceBuilderTests.cs +++ b/AppBoot/iQuarc.AppBoot.UnitTests/ServiceBuilderTests.cs @@ -160,6 +160,17 @@ public void GetServicesFrom_ExportBuilderWithMultipleConfigs_AllConfigurationsEx AssertEx.AreEquivalent(services, comparer.Equals, expected); } + [Fact] + public void GetServicesFrom_NoTypeMatch_DoesNotExport() + { + ServiceBuilder builder = new ServiceBuilder(t => t == typeof(MyService)); + builder.Export(); + + ServiceInfo actual = builder.GetServicesFrom(typeof(IMyService1)).FirstOrDefault(); + + Assert.Null(actual); + } + private class MyService : IMyService1, IMyService2 { } diff --git a/AppBoot/iQuarc.AppBoot.UnitTests/ServiceRegistrationBehaviorTests.cs b/AppBoot/iQuarc.AppBoot.UnitTests/ServiceRegistrationBehaviorTests.cs index 7066107..75deab6 100644 --- a/AppBoot/iQuarc.AppBoot.UnitTests/ServiceRegistrationBehaviorTests.cs +++ b/AppBoot/iQuarc.AppBoot.UnitTests/ServiceRegistrationBehaviorTests.cs @@ -100,12 +100,4 @@ private class MyDoubleService : IMyService { } } - - public static class Extensions - { - public static T[] AsArray(this T o) - { - return new[] {o}; - } - } } \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs b/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs index 7846bb4..4f8b334 100644 --- a/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs +++ b/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs @@ -1,14 +1,13 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Linq; namespace iQuarc.AppBoot { - public class ConventionRegistrationBehavior : IRegistrationBehavior, IContainer + public class ConventionRegistrationBehavior : IRegistrationBehavior { private readonly IList builders = new List(); - + public IEnumerable GetServicesFrom(Type type) { IEnumerable services = builders.SelectMany(x => x.GetServicesFrom(type)); @@ -46,24 +45,10 @@ public ServiceBuilder ForTypesMatching(Predicate typeFilter) return builder; } - void IContainer.Register(ServiceBuilder builder) - { - this.builders.Add(builder); - } - private ServiceBuilder CreateServiceBuilder(Predicate typeFilter) + private static ServiceBuilder CreateServiceBuilder(Predicate typeFilter) { return new ServiceBuilder(typeFilter); } - - public IEnumerator GetEnumerator() - { - return builders.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } } } \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot/Container/IContainer.cs b/AppBoot/iQuarc.AppBoot/Container/IContainer.cs deleted file mode 100644 index 6836dd9..0000000 --- a/AppBoot/iQuarc.AppBoot/Container/IContainer.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace iQuarc.AppBoot -{ - public interface IContainer : IEnumerable - { - void Register(T item); - } -} \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs b/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs index d56387e..f1a7886 100644 --- a/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs +++ b/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs @@ -21,7 +21,7 @@ public void Export() public void Export(Action exportConfiguration) { - configs.Add(new ExportConfig { ContractsProvider = t => new[] { t }, ExportConfiguration = exportConfiguration }); + RegisterConfig(new ExportConfig { ContractsProvider = t => new[] { t }, ExportConfiguration = exportConfiguration }); } public void ExportInterfaces() @@ -38,7 +38,7 @@ public void ExportInterfaces(Predicate interfaceFilter, Action> interfaces = t => t.GetInterfaces().Where(x => interfaceFilter(x)); - configs.Add(new ExportConfig { ExportConfiguration = exportConfiguration, ContractsProvider = interfaces }); + RegisterConfig(new ExportConfig { ExportConfiguration = exportConfiguration, ContractsProvider = interfaces }); } public bool IsMatch(Type type) diff --git a/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj b/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj index 0f02621..31b2bd0 100644 --- a/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj +++ b/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj @@ -59,7 +59,6 @@ - From afa4481610cc4d9eb1b1cf003b4457a9e39e4b86 Mon Sep 17 00:00:00 2001 From: Florin Date: Fri, 5 Dec 2014 09:45:44 +0200 Subject: [PATCH 4/7] make few members private from internal --- AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs b/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs index f1a7886..f8e175a 100644 --- a/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs +++ b/AppBoot/iQuarc.AppBoot/Container/ServiceBuilder.cs @@ -67,12 +67,12 @@ internal IEnumerable GetServicesFrom(Type type) } } - internal void RegisterConfig(ExportConfig config) + private void RegisterConfig(ExportConfig config) { this.configs.Add(config); } - internal class ExportConfig + private class ExportConfig { internal Action ExportConfiguration { get; set; } From 70ca953ac58bccac97d7aec9e990c3974767ec60 Mon Sep 17 00:00:00 2001 From: Florin Date: Wed, 17 Dec 2014 16:10:41 +0200 Subject: [PATCH 5/7] add gitignore --- .gitignore | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd5204b --- /dev/null +++ b/.gitignore @@ -0,0 +1,183 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# If using the old MSBuild-Integrated Package Restore, uncomment this: +#!**/packages/repositories.config + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ From d15e97756e64a751b96fbf523a07ba55c9597b94 Mon Sep 17 00:00:00 2001 From: Florin Date: Tue, 24 Feb 2015 17:39:51 +0200 Subject: [PATCH 6/7] update used packages and fix CA --- AppBoot/iQuarc.AppBoot.UnitTests/app.config | 11 ++++++++++ .../iQuarc.AppBoot.UnitTests.csproj | 11 ++++++---- .../iQuarc.AppBoot.UnitTests/packages.config | 4 ++-- ...uarc.AppBoot.Unity.ExploratoryTests.csproj | 12 +++++++---- .../packages.config | 2 +- .../ConventionRegistrationBehavior.cs | 13 +++++++----- .../iQuarc.AppBoot/Container/ExportBuilder.cs | 2 ++ AppBoot/iQuarc.AppBoot/GlobalSuppressions.cs | Bin 0 -> 1638 bytes AppBoot/iQuarc.AppBoot/app.config | 11 ++++++++++ AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj | 20 +++++++++++------- AppBoot/iQuarc.AppBoot/packages.config | 4 ++-- 11 files changed, 64 insertions(+), 26 deletions(-) create mode 100644 AppBoot/iQuarc.AppBoot.UnitTests/app.config create mode 100644 AppBoot/iQuarc.AppBoot/GlobalSuppressions.cs create mode 100644 AppBoot/iQuarc.AppBoot/app.config diff --git a/AppBoot/iQuarc.AppBoot.UnitTests/app.config b/AppBoot/iQuarc.AppBoot.UnitTests/app.config new file mode 100644 index 0000000..4fc378d --- /dev/null +++ b/AppBoot/iQuarc.AppBoot.UnitTests/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot.UnitTests/iQuarc.AppBoot.UnitTests.csproj b/AppBoot/iQuarc.AppBoot.UnitTests/iQuarc.AppBoot.UnitTests.csproj index e0ee278..7580ec9 100644 --- a/AppBoot/iQuarc.AppBoot.UnitTests/iQuarc.AppBoot.UnitTests.csproj +++ b/AppBoot/iQuarc.AppBoot.UnitTests/iQuarc.AppBoot.UnitTests.csproj @@ -42,12 +42,14 @@ ..\packages\iQuarc.xUnitEx.1.0.0.0\lib\net35\iQuarc.xUnitEx.dll - - ..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll + + False + ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll - - ..\packages\Moq.4.2.1312.1622\lib\net40\Moq.dll + + False + ..\packages\Moq.4.2.1502.0911\lib\net40\Moq.dll @@ -73,6 +75,7 @@ + diff --git a/AppBoot/iQuarc.AppBoot.UnitTests/packages.config b/AppBoot/iQuarc.AppBoot.UnitTests/packages.config index 0819a72..faafa01 100644 --- a/AppBoot/iQuarc.AppBoot.UnitTests/packages.config +++ b/AppBoot/iQuarc.AppBoot.UnitTests/packages.config @@ -1,8 +1,8 @@  - + - + \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot.Unity.ExplorationTests/iQuarc.AppBoot.Unity.ExploratoryTests.csproj b/AppBoot/iQuarc.AppBoot.Unity.ExplorationTests/iQuarc.AppBoot.Unity.ExploratoryTests.csproj index 249fb3a..fffd0ef 100644 --- a/AppBoot/iQuarc.AppBoot.Unity.ExplorationTests/iQuarc.AppBoot.Unity.ExploratoryTests.csproj +++ b/AppBoot/iQuarc.AppBoot.Unity.ExplorationTests/iQuarc.AppBoot.Unity.ExploratoryTests.csproj @@ -39,13 +39,17 @@ False ..\packages\iQuarc.xUnitEx.1.0.0.0\lib\net35\iQuarc.xUnitEx.dll - + False - ..\packages\Unity.3.0.1304.1\lib\Net45\Microsoft.Practices.Unity.dll + ..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.dll - + False - ..\packages\Unity.3.0.1304.1\lib\Net45\Microsoft.Practices.Unity.Configuration.dll + ..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.Configuration.dll + + + False + ..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll diff --git a/AppBoot/iQuarc.AppBoot.Unity.ExplorationTests/packages.config b/AppBoot/iQuarc.AppBoot.Unity.ExplorationTests/packages.config index 80b22f1..d418a2e 100644 --- a/AppBoot/iQuarc.AppBoot.Unity.ExplorationTests/packages.config +++ b/AppBoot/iQuarc.AppBoot.Unity.ExplorationTests/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs b/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs index 4f8b334..e4c17c2 100644 --- a/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs +++ b/AppBoot/iQuarc.AppBoot/Container/ConventionRegistrationBehavior.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; namespace iQuarc.AppBoot @@ -13,14 +14,15 @@ public IEnumerable GetServicesFrom(Type type) IEnumerable services = builders.SelectMany(x => x.GetServicesFrom(type)); return services; } - + public ServiceBuilder ForType(Type type) { ServiceBuilder builder = CreateServiceBuilder(x => x == type); builders.Add(builder); - return builder; + return builder; } + [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "Convenience call")] public ServiceBuilder ForType() { return this.ForType(typeof (T)); @@ -29,10 +31,11 @@ public ServiceBuilder ForType() public ServiceBuilder ForTypesDerivedFrom(Type type) { ServiceBuilder builder = CreateServiceBuilder(x => type.IsAssignableFrom(x)); - builders.Add(builder); - return builder; + builders.Add(builder); + return builder; } + [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "Convenience call")] public ServiceBuilder ForTypesDerivedFrom() { return ForTypesDerivedFrom(typeof (T)); @@ -41,7 +44,7 @@ public ServiceBuilder ForTypesDerivedFrom() public ServiceBuilder ForTypesMatching(Predicate typeFilter) { ServiceBuilder builder = CreateServiceBuilder(typeFilter); - builders.Add(builder); + builders.Add(builder); return builder; } diff --git a/AppBoot/iQuarc.AppBoot/Container/ExportBuilder.cs b/AppBoot/iQuarc.AppBoot/Container/ExportBuilder.cs index 3b8fb11..ac2ebc8 100644 --- a/AppBoot/iQuarc.AppBoot/Container/ExportBuilder.cs +++ b/AppBoot/iQuarc.AppBoot/Container/ExportBuilder.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; namespace iQuarc.AppBoot { @@ -20,6 +21,7 @@ public ExportBuilder AsContractType(Type type) return this; } + [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "Convenience call")] public ExportBuilder AsContractType() { return AsContractType(typeof (T)); diff --git a/AppBoot/iQuarc.AppBoot/GlobalSuppressions.cs b/AppBoot/iQuarc.AppBoot/GlobalSuppressions.cs new file mode 100644 index 0000000000000000000000000000000000000000..0b11a84858dccf264d6439fe8bb36f6e95917f7a GIT binary patch literal 1638 zcmeH{L2uJQ5QXQA#DB1S0;x^mgh1+{Ekf#{2$Wn9>cJ##Vu+n8wvqDZf$z<9WycZx z0%RrY-I;y!=FNJ@;CkyQj6VwIe;ZXRr{Df?FMa714U$5MT$Qto%%)is@ocMIy)zhs{i4R28q~s$- zGy4LY9#$(?RQ;izXz&|%YEt^|9XIXhq;t$yLk!KHrZ2i%yuWfLeWU8Ky(9MACseak zZ+&Do9TB<;j-&l5AP>;m_gk5Dta57lF(e%uze|%k%<@CD}Ixnci@RdsnfA&t?gEFJK`YK<8r>-Bg{{!$h8VCRY literal 0 HcmV?d00001 diff --git a/AppBoot/iQuarc.AppBoot/app.config b/AppBoot/iQuarc.AppBoot/app.config new file mode 100644 index 0000000..4fc378d --- /dev/null +++ b/AppBoot/iQuarc.AppBoot/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj b/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj index 31b2bd0..765ef3c 100644 --- a/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj +++ b/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.csproj @@ -35,16 +35,18 @@ False ..\packages\iQuarc.SystemEx.1.0.0.0\lib\net40\iQuarc.SystemEx.dll - - ..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll - - + False - ..\packages\Unity.3.0.1304.1\lib\Net45\Microsoft.Practices.Unity.dll + ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll - - False - ..\packages\Unity.3.0.1304.1\lib\Net45\Microsoft.Practices.Unity.Configuration.dll + + ..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.dll + + + ..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.Configuration.dll + + + ..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll @@ -62,6 +64,7 @@ + @@ -75,6 +78,7 @@ + diff --git a/AppBoot/iQuarc.AppBoot/packages.config b/AppBoot/iQuarc.AppBoot/packages.config index 1a6f383..2a12d3e 100644 --- a/AppBoot/iQuarc.AppBoot/packages.config +++ b/AppBoot/iQuarc.AppBoot/packages.config @@ -1,6 +1,6 @@  - + - + \ No newline at end of file From 0a8a370583991e575ce9b8e9489db0e834b08c55 Mon Sep 17 00:00:00 2001 From: Florin Date: Mon, 2 Mar 2015 15:54:51 +0200 Subject: [PATCH 7/7] prepare for release v.1.1.0 --- AppBoot/iQuarc.AppBoot/Properties/AssemblyInfo.cs | 4 ++-- AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.nuspec | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AppBoot/iQuarc.AppBoot/Properties/AssemblyInfo.cs b/AppBoot/iQuarc.AppBoot/Properties/AssemblyInfo.cs index 051f9c4..8528636 100644 --- a/AppBoot/iQuarc.AppBoot/Properties/AssemblyInfo.cs +++ b/AppBoot/iQuarc.AppBoot/Properties/AssemblyInfo.cs @@ -45,5 +45,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.1.0.0")] +[assembly: AssemblyFileVersion("1.1.0.0")] \ No newline at end of file diff --git a/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.nuspec b/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.nuspec index 6f5d194..d2f3418 100644 --- a/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.nuspec +++ b/AppBoot/iQuarc.AppBoot/iQuarc.AppBoot.nuspec @@ -9,7 +9,7 @@ false $description$ $description$ - Basic functionality for hiding the DI Container and for defining a modular application. + Adds registrations by convention support. Copyright 2014 Dependency Injection Modularity Bootstrap Configuration https://raw.githubusercontent.com/iQuarc/AppBoot/master/MIT.md