diff options
Diffstat (limited to 'slips/src/app/Marina/Infrastructure/Container')
5 files changed, 74 insertions, 0 deletions
diff --git a/slips/src/app/Marina/Infrastructure/Container/Custom/CustomDependencyContainer.cs b/slips/src/app/Marina/Infrastructure/Container/Custom/CustomDependencyContainer.cs new file mode 100644 index 0000000..d37e452 --- /dev/null +++ b/slips/src/app/Marina/Infrastructure/Container/Custom/CustomDependencyContainer.cs @@ -0,0 +1,21 @@ +using System;
+using System.Collections.Generic;
+
+namespace Marina.Infrastructure.Container.Custom {
+ public class CustomDependencyContainer : IDependencyContainer {
+ private static IDictionary< Type, object > list;
+
+ public CustomDependencyContainer( ) {
+ list = new Dictionary< Type, object >( );
+ }
+
+ public Interface GetMeAnImplementationOfAn< Interface >( ) {
+ Type currentType = typeof( Interface );
+ return ( Interface )list[ currentType ];
+ }
+
+ public void AddImplementationOf< Interface >( Interface objectToRegister ) {
+ list.Add( typeof( Interface ), objectToRegister );
+ }
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Infrastructure/Container/IDependencyContainer.cs b/slips/src/app/Marina/Infrastructure/Container/IDependencyContainer.cs new file mode 100644 index 0000000..3533e23 --- /dev/null +++ b/slips/src/app/Marina/Infrastructure/Container/IDependencyContainer.cs @@ -0,0 +1,5 @@ +namespace Marina.Infrastructure.Container {
+ public interface IDependencyContainer {
+ Interface GetMeAnImplementationOfAn< Interface >( );
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Infrastructure/Container/InterfaceResolutionException.cs b/slips/src/app/Marina/Infrastructure/Container/InterfaceResolutionException.cs new file mode 100644 index 0000000..d42b550 --- /dev/null +++ b/slips/src/app/Marina/Infrastructure/Container/InterfaceResolutionException.cs @@ -0,0 +1,11 @@ +using System;
+
+namespace Marina.Infrastructure.Container {
+ public class InterfaceResolutionException : Exception {
+ public const string ExceptionMessageFormat = "Failed to resolve an implementation of an {0}";
+
+ public InterfaceResolutionException( Exception innerException, Type interfaceThatCouldNotBeResolvedForSomeReason )
+ : base(
+ string.Format( ExceptionMessageFormat, interfaceThatCouldNotBeResolvedForSomeReason.FullName ), innerException ) {}
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Infrastructure/Container/Resolve.cs b/slips/src/app/Marina/Infrastructure/Container/Resolve.cs new file mode 100644 index 0000000..53e602b --- /dev/null +++ b/slips/src/app/Marina/Infrastructure/Container/Resolve.cs @@ -0,0 +1,21 @@ +using System;
+
+namespace Marina.Infrastructure.Container {
+ public class Resolve {
+ private static IDependencyContainer container;
+
+ public static void InitializeWith( IDependencyContainer newContainer
+ ) {
+ container = newContainer;
+ }
+
+ public static Interface DependencyFor< Interface >() {
+ try {
+ return container.GetMeAnImplementationOfAn< Interface >( );
+ }
+ catch ( Exception e ) {
+ throw new InterfaceResolutionException( e, typeof( Interface ) );
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Infrastructure/Container/Windsor/WindsorDependencyContainer.cs b/slips/src/app/Marina/Infrastructure/Container/Windsor/WindsorDependencyContainer.cs new file mode 100644 index 0000000..c35c6ce --- /dev/null +++ b/slips/src/app/Marina/Infrastructure/Container/Windsor/WindsorDependencyContainer.cs @@ -0,0 +1,16 @@ +using Castle.Windsor;
+using Castle.Windsor.Configuration.Interpreters;
+
+namespace Marina.Infrastructure.Container.Windsor {
+ public class WindsorDependencyContainer : IDependencyContainer {
+ private readonly IWindsorContainer _container;
+
+ public WindsorDependencyContainer() {
+ _container = new WindsorContainer( new XmlInterpreter( @"windsor.config.xml" ) );
+ }
+
+ public Interface GetMeAnImplementationOfAn< Interface >() {
+ return _container.Resolve< Interface >( );
+ }
+ }
+}
\ No newline at end of file |
