Click here to Skip to main content
15,884,298 members
Articles / Programming Languages / C#

MetaContainer - an abstraction over the dependency injection infrastructure

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
7 Mar 2009Ms-PL3 min read 20.5K   82   10  
Description of an abstraction layer over the dependency injection infrastructure
using MetaContainer;
using NUnit.Framework;
using Rhino.Mocks;

namespace Tests.MetaContainer
{
   [TestFixture]
   public class ExtensionMethodsTest
   {
      private MockRepository _mocks;

      [SetUp]
      public void SetUp()
      {
         _mocks = new MockRepository();
      }

      [Test]
      public void RegisterWithoutName()
      {
         IMetaContainer container = _mocks.CreateMock<IMetaContainer>();
         using (_mocks.Record())
         {
            container.Register(typeof(ITestInterface), typeof(SampleTestImpl), null);
         }

         using (_mocks.Playback())
         {
            container.Register(typeof(ITestInterface), typeof(SampleTestImpl));
         }
      }

      [Test]
      public void RegisterGenericWithName()
      {
         IMetaContainer container = _mocks.CreateMock<IMetaContainer>();
         using (_mocks.Record())
         {
            container.Register(typeof(ITestInterface), typeof(SampleTestImpl), null);
         }

         using (_mocks.Playback())
         {
            container.Register(typeof(ITestInterface), typeof(SampleTestImpl));
         }
      }

      [Test]
      public void GenericFactoryMethodRegistrationIsForwardedToNonGenericOne()
      {
         IMetaContainer container = _mocks.CreateMock<IMetaContainer>();
         using (_mocks.Record())
         {            
            container.Register(typeof(ITestInterface), name => new SampleTestImpl(), "name", Scope.Transient);
            LastCall.IgnoreArguments();
            container.Register(typeof(ITestInterface), name => new SampleTestImpl(), null, Scope.Transient);
            LastCall.IgnoreArguments();
         }

         using (_mocks.Playback())
         {
            container.Register<ITestInterface>(name => new SampleTestImpl(), "name"); 
            container.Register<ITestInterface>(name => new SampleTestImpl());            
         }
      }
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Software Developer (Senior) VSoft
Poland Poland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions