<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/rss.xsl"?><rss version="2.0"><channel><title>Munq Discussions Rss Feed</title><link>http://munq.codeplex.com/Thread/List.aspx</link><description>Munq Discussions Rss Description</description><item><title>New Post: Support for WebApi dependency resolver.</title><link>http://munq.codeplex.com/discussions/433496</link><description>&lt;div style="line-height: normal;"&gt;
&lt;div&gt;
&lt;div style="font-family:Calibri,sans-serif; font-size:11pt"&gt;No, life got busy.&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;span style="font-family:Tahoma,sans-serif; font-size:10pt; font-weight:bold"&gt;From:
&lt;/span&gt;&lt;span style="font-family:Tahoma,sans-serif; font-size:10pt"&gt;ctolkien&lt;/span&gt;&lt;br&gt;
&lt;span style="font-family:Tahoma,sans-serif; font-size:10pt; font-weight:bold"&gt;Sent:
&lt;/span&gt;&lt;span style="font-family:Tahoma,sans-serif; font-size:10pt"&gt;11/04/2013 12:13 AM&lt;/span&gt;&lt;br&gt;
&lt;span style="font-family:Tahoma,sans-serif; font-size:10pt; font-weight:bold"&gt;To:
&lt;/span&gt;&lt;span style="font-family:Tahoma,sans-serif; font-size:10pt"&gt;[email removed]&lt;/span&gt;&lt;br&gt;
&lt;span style="font-family:Tahoma,sans-serif; font-size:10pt; font-weight:bold"&gt;Subject:
&lt;/span&gt;&lt;span style="font-family:Tahoma,sans-serif; font-size:10pt"&gt;Re: Support for WebApi dependency resolver. [Munq:433496]&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;p&gt;From: ctolkien&lt;/p&gt;
&lt;div id="ThreadNotificationPostBody"&gt;&lt;strong&gt;mdennis wrote:&lt;/strong&gt;&lt;br&gt;
&lt;blockquote&gt;I will create an article on CodeProject this weekend to explain how to do this.&lt;br&gt;
&lt;br&gt;
I will probably create a Nuget package as a result/&lt;br&gt;
&lt;/blockquote&gt;
Hi mdennis, &lt;br&gt;
&lt;br&gt;
Did you have a chance to make any progress on this?&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;</description><author>mdennis</author><pubDate>Thu, 11 Apr 2013 12:18:15 GMT</pubDate><guid isPermaLink="false">New Post: Support for WebApi dependency resolver. 20130411121815P</guid></item><item><title>New Post: Support for WebApi dependency resolver.</title><link>http://munq.codeplex.com/discussions/433496</link><description>&lt;div style="line-height: normal;"&gt;&lt;strong&gt;mdennis wrote:&lt;/strong&gt;&lt;br /&gt;
&lt;blockquote&gt;
I will create an article on CodeProject this weekend to explain how to do this.&lt;br /&gt;
&lt;br /&gt;
I will probably create a Nuget package as a result/&lt;br /&gt;
&lt;/blockquote&gt;
Hi mdennis,&lt;br /&gt;
&lt;br /&gt;
Did you have a chance to make any progress on this?&lt;br /&gt;
&lt;/div&gt;</description><author>ctolkien</author><pubDate>Thu, 11 Apr 2013 04:13:37 GMT</pubDate><guid isPermaLink="false">New Post: Support for WebApi dependency resolver. 20130411041337A</guid></item><item><title>New Post: Request/Thread singletons in MVC projects</title><link>http://munq.codeplex.com/discussions/439707</link><description>&lt;div style="line-height: normal;"&gt;Hi. &lt;br /&gt;
&lt;br /&gt;
I have a service which I want to use PerRequest for contollers, but PerThread for code kicked off via TaskFactory.StartNew (which I am getting hold of using Munq.MVC3.MunqDependencyResolver.Container.Resolve&amp;lt;T&amp;gt; in the task).&lt;br /&gt;
&lt;br /&gt;
Which should I register the service with? Is there a mixed mode, which uses PerThread when HttpContext.Current is null, or some other approach I should take?&lt;br /&gt;
&lt;br /&gt;
thanks!&lt;br /&gt;
&lt;/div&gt;</description><author>mcintyre321</author><pubDate>Tue, 09 Apr 2013 22:10:55 GMT</pubDate><guid isPermaLink="false">New Post: Request/Thread singletons in MVC projects 20130409101055P</guid></item><item><title>New Post: Support for WebApi dependency resolver.</title><link>http://munq.codeplex.com/discussions/433496</link><description>&lt;div style="line-height: normal;"&gt;I suspected something like that. Thank you in advance.&lt;br /&gt;
&lt;/div&gt;</description><author>jogai</author><pubDate>Fri, 08 Mar 2013 07:11:27 GMT</pubDate><guid isPermaLink="false">New Post: Support for WebApi dependency resolver. 20130308071127A</guid></item><item><title>New Post: Is it possible to put Xml doc in NuGet package?</title><link>http://munq.codeplex.com/discussions/406713</link><description>&lt;div style="line-height: normal;"&gt;Yeah, I forgot to include the .XML file.  I'll fix that shortly.  Sorry.&lt;br /&gt;
&lt;/div&gt;</description><author>mdennis</author><pubDate>Fri, 08 Mar 2013 04:00:49 GMT</pubDate><guid isPermaLink="false">New Post: Is it possible to put Xml doc in NuGet package? 20130308040049A</guid></item><item><title>New Post: Dynamic component resolution</title><link>http://munq.codeplex.com/discussions/435698</link><description>&lt;div style="line-height: normal;"&gt;Personally, I rarely use the first option either.  At the CodeProject, we use the second as well and it very nicely prevents the coupling caused by having to do all your registration in your top level executable.  Your app really doesn't need to know what class is implementing the Interfaces.&lt;br /&gt;
&lt;br /&gt;
Another variation is to create a Configuration project that just has a Class (or Classes) that implement the IMunqConfig Interface, and defines the IOC configuration.  It is the only thing that needs to know about everything.  Just drop this dll into the bin directory and you are configured.&lt;br /&gt;
&lt;/div&gt;</description><author>mdennis</author><pubDate>Fri, 08 Mar 2013 03:59:03 GMT</pubDate><guid isPermaLink="false">New Post: Dynamic component resolution 20130308035903A</guid></item><item><title>New Post: Support for WebApi dependency resolver.</title><link>http://munq.codeplex.com/discussions/433496</link><description>&lt;div style="line-height: normal;"&gt;I didn't used to be like that, but we've made some changes that may have messed some articles up.  I'll clean them up, and update the articles.&lt;br /&gt;
&lt;/div&gt;</description><author>mdennis</author><pubDate>Fri, 08 Mar 2013 03:45:52 GMT</pubDate><guid isPermaLink="false">New Post: Support for WebApi dependency resolver. 20130308034552A</guid></item><item><title>New Post: Support for WebApi dependency resolver.</title><link>http://munq.codeplex.com/discussions/433496</link><description>&lt;div style="line-height: normal;"&gt;Can I point out that the code on CodeProject is very hard to read since there are a lot of html spans in it? Example: &lt;a href="http://www.codeproject.com/Articles/83416/Munq-IocContainer-V2-Overview" rel="nofollow"&gt;http://www.codeproject.com/Articles/83416/Munq-IocContainer-V2-Overview&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>jogai</author><pubDate>Fri, 08 Mar 2013 02:50:27 GMT</pubDate><guid isPermaLink="false">New Post: Support for WebApi dependency resolver. 20130308025027A</guid></item><item><title>New Post: Is it possible to put Xml doc in NuGet package?</title><link>http://munq.codeplex.com/discussions/406713</link><description>&lt;div style="line-height: normal;"&gt;For me there is. Try adding some usings:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;using Munq;
using Munq.Configuration;
using Munq.MVC3;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;</description><author>jogai</author><pubDate>Fri, 08 Mar 2013 02:46:39 GMT</pubDate><guid isPermaLink="false">New Post: Is it possible to put Xml doc in NuGet package? 20130308024639A</guid></item><item><title>New Post: Dynamic component resolution</title><link>http://munq.codeplex.com/discussions/435698</link><description>&lt;div style="line-height: normal;"&gt;Thanks for the answer.&lt;br /&gt;
&lt;br /&gt;
I'll use the second option so I can remove the dependency to the layer with the concrete implementation.&lt;br /&gt;
&lt;/div&gt;</description><author>jogai</author><pubDate>Fri, 08 Mar 2013 02:44:09 GMT</pubDate><guid isPermaLink="false">New Post: Dynamic component resolution 20130308024409A</guid></item><item><title>New Post: Support for WebApi dependency resolver.</title><link>http://munq.codeplex.com/discussions/433496</link><description>&lt;div style="line-height: normal;"&gt;I will create an article on CodeProject this weekend to explain how to do this.&lt;br /&gt;
&lt;br /&gt;
I will probably create a Nuget package as a result/&lt;br /&gt;
&lt;/div&gt;</description><author>mdennis</author><pubDate>Fri, 08 Mar 2013 02:13:21 GMT</pubDate><guid isPermaLink="false">New Post: Support for WebApi dependency resolver. 20130308021321A</guid></item><item><title>New Post: Register Areas</title><link>http://munq.codeplex.com/discussions/435814</link><description>&lt;div style="line-height: normal;"&gt;The Munq.MVC3 package on Nuget adds Munq to your MVC3 or 4 application.  Areas are handled correctly as the MVC framework asks the IOC container for a Class, not an instance, and Munq knows how to create classes without registering the classes in advance.&lt;br /&gt;
&lt;br /&gt;
The first time it creates an instance of a Class, it uses Reflection to determine the Constructor with the most parameters, and then creates a delegate which uses this constructor, calling Munq.Resolve(Type type) for each of the parameters.&lt;br /&gt;
&lt;br /&gt;
So, while I haven't tried this particular scenario, it should just work without any Registering of the Areas in Munq.&lt;br /&gt;
&lt;/div&gt;</description><author>mdennis</author><pubDate>Fri, 08 Mar 2013 02:08:54 GMT</pubDate><guid isPermaLink="false">New Post: Register Areas 20130308020854A</guid></item><item><title>New Post: Dynamic component resolution</title><link>http://munq.codeplex.com/discussions/435698</link><description>&lt;div style="line-height: normal;"&gt;There are two ways to accomplish this.  The first is to use named registration&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;    container.Register&amp;lt;IColoredComponent, BlueComponent&amp;gt;(&amp;quot;Blue&amp;quot;);
    container.Register&amp;lt;IColoredComponent, RedComponent&amp;gt;(&amp;quot;Red&amp;quot;);

   ....

   string myFavoriteColor = ReadMyFavoriteColorFromConfigFIle();
   var coloredComponent = container.Resolve&amp;lt;IColoredComponent&amp;gt;(myFavoriteColor);&lt;/code&gt;&lt;/pre&gt;

The other is to use the AutoRegistration feature of Munq.&lt;br /&gt;
If you call &lt;em&gt;Munq.Configuration.ConfigurationLoader(IocContainer  container)&lt;/em&gt;, the dlls in the /bin directory will be searched for classes that implement the IMunqConfig interface.&lt;br /&gt;
An instance will be created of each of the classes found, and the &lt;em&gt;RegisterIn(IocContainer container)&lt;/em&gt; method will be called.  The class can then do whatever registration is required.  Now you can configure your application by just dropping the 'correct' dll(s) into the \bin directory.&lt;br /&gt;
&lt;/div&gt;</description><author>mdennis</author><pubDate>Fri, 08 Mar 2013 01:56:40 GMT</pubDate><guid isPermaLink="false">New Post: Dynamic component resolution 20130308015640A</guid></item><item><title>New Post: Register Areas</title><link>http://munq.codeplex.com/discussions/435814</link><description>&lt;div style="line-height: normal;"&gt;Hello,&lt;br /&gt;
&lt;br /&gt;
I'm working on a large MVC app that required my group to make plug-able areas something similar to this &lt;a href="http://nileshhirapra.blogspot.sg/2012/02/aspnet-mvc-pluggable-application.html" rel="nofollow"&gt;http://nileshhirapra.blogspot.sg/2012/02/aspnet-mvc-pluggable-application.html&lt;/a&gt;. Now I'm trying to make use of Munq in my MVC app to register the Areas and cant figure out what I need to do to register Areas.&lt;br /&gt;
&lt;br /&gt;
I was looking at this article &lt;a href="http://www.codeproject.com/Articles/43354/Using-Munq-IOC-with-ASP-NET-MVC-2-Preview-2" rel="nofollow"&gt;http://www.codeproject.com/Articles/43354/Using-Munq-IOC-with-ASP-NET-MVC-2-Preview-2&lt;/a&gt; which states &amp;quot;Note: This version of the MunqControllerFactory does not support the Areas feature of MVC 2. This too will be corrected in a future article.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
I guess the questions is how can I register an Area using Munq?&lt;br /&gt;
&lt;br /&gt;
Thanks,&lt;br /&gt;
Kris&lt;br /&gt;
&lt;/div&gt;</description><author>KCavitt</author><pubDate>Thu, 07 Mar 2013 21:22:17 GMT</pubDate><guid isPermaLink="false">New Post: Register Areas 20130307092217P</guid></item><item><title>New Post: Dynamic component resolution</title><link>http://munq.codeplex.com/discussions/435698</link><description>&lt;div style="line-height: normal;"&gt;Is it possible to load the dependencies dynamicly? And if so how?&lt;br /&gt;
&lt;br /&gt;
An example is given here under the title &amp;quot;Dynamic component resolution&amp;quot; : &lt;a href="http://www.devtrends.co.uk/blog/how-not-to-do-dependency-injection-the-static-or-singleton-container" rel="nofollow"&gt;http://www.devtrends.co.uk/blog/how-not-to-do-dependency-injection-the-static-or-singleton-container&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
This way we can load the proper dependency based on configuration.&lt;br /&gt;
&lt;/div&gt;</description><author>jogai</author><pubDate>Thu, 07 Mar 2013 08:14:20 GMT</pubDate><guid isPermaLink="false">New Post: Dynamic component resolution 20130307081420A</guid></item><item><title>New Post: Support for WebApi dependency resolver.</title><link>http://munq.codeplex.com/discussions/433496</link><description>&lt;div style="line-height: normal;"&gt;As per the title!&lt;br /&gt;
&lt;/div&gt;</description><author>ctolkien</author><pubDate>Mon, 18 Feb 2013 07:31:11 GMT</pubDate><guid isPermaLink="false">New Post: Support for WebApi dependency resolver. 20130218073111A</guid></item><item><title>New Post: Is it possible to put Xml doc in NuGet package?</title><link>http://munq.codeplex.com/discussions/406713</link><description>&lt;div style="line-height: normal;"&gt;
&lt;p&gt;Hi, I just start using munq and I like it so far. Great work!&lt;/p&gt;
&lt;p&gt;Current when using munq there is not IntelliSense help on the methods. Is it possible to put it in there?&lt;/p&gt;
&lt;/div&gt;</description><author>unional</author><pubDate>Thu, 13 Dec 2012 23:59:30 GMT</pubDate><guid isPermaLink="false">New Post: Is it possible to put Xml doc in NuGet package? 20121213115930P</guid></item><item><title>New Post: Requestlifetime issue</title><link>http://munq.codeplex.com/discussions/347658</link><description>&lt;div style="line-height: normal;"&gt;
&lt;p&gt;yes&lt;/p&gt;
&lt;/div&gt;</description><author>chenyunjiang</author><pubDate>Wed, 28 Nov 2012 03:58:56 GMT</pubDate><guid isPermaLink="false">New Post: Requestlifetime issue 20121128035856A</guid></item><item><title>New Post: Lazy Load Injection</title><link>http://munq.codeplex.com/discussions/395757</link><description>&lt;div style="line-height: normal;"&gt;
&lt;p&gt;Hello Dennis,&lt;/p&gt;
&lt;p&gt;There is Unit of Work Pattern&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div style="color:black; background-color:white"&gt;
&lt;pre&gt;&lt;span style="color:blue"&gt;public&lt;/span&gt; &lt;span style="color:blue"&gt;interface&lt;/span&gt; IUnitOfWork {
    IRepository&amp;lt;Employee&amp;gt; Employees { &lt;span style="color:blue"&gt;get&lt;/span&gt;; }
    IRepository&amp;lt;TimeCard&amp;gt; TimeCards { &lt;span style="color:blue"&gt;get&lt;/span&gt;;  }
    &lt;span style="color:blue"&gt;void&lt;/span&gt; Commit();
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It will contain all repositories from aplication. Everything i need to setup is to resolver IUnitOfWork interface and another interfaces will be automatically resolved. But problem here is that i dont need all repos and dont want them even created until
 i call them. Is there any hack to do that or it is already work in this way?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Dima.&lt;/p&gt;
&lt;/div&gt;</description><author>F0rc0sigan</author><pubDate>Mon, 17 Sep 2012 05:37:05 GMT</pubDate><guid isPermaLink="false">New Post: Lazy Load Injection 20120917053705A</guid></item><item><title>New Post: Requestlifetime issue</title><link>http://munq.codeplex.com/discussions/347658</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;I have used the RequestLifeTime before this fix and had no problem. Using Http session lifetime with repositories (especially using IoC and OrM mapped to db) is tricky once. Looking at your code:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;[InvalidOperationException: Event handlers can only be bound to HttpApplication events during IHttpModule initialization.]&lt;/pre&gt;
&lt;p&gt;may is due to impedance mismatch. This is frequent happening when object should be created on early bound instead of late binding or data has yet to be fetched completely.&amp;nbsp; According to Ayende, &lt;strong&gt;singleton request&lt;/strong&gt; usually creates problems for database request when using IoC with OrM. Maybe&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre style="font-family: Consolas; background: white; color: black; font-size: 13px;"&gt;&lt;pre style="font-family: Consolas; background: white; color: black; font-size: 13px;"&gt;&lt;strong&gt;.AsRequestSingleton();&lt;/strong&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;is the culprit. See my code below which I hope could give some insights for your implementation coz I have don't have much time to review the whole error messages:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Architecture 1 :: Class Library :: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DB&amp;gt;&amp;gt;IDB&amp;gt;&amp;gt;Petapoco&amp;gt;&amp;gt;Models&amp;gt;&amp;gt;Object Repository(Implementation)&amp;gt;&amp;gt;IRepository&lt;/p&gt;
&lt;p&gt;Architecture 2 :: MVC4 WebAPI :: &amp;nbsp; Controller&amp;gt;&amp;gt;Resolve IRepository&amp;gt;&amp;gt; Bootstrapper &amp;gt;&amp;gt; MunqRequestLifeTime &amp;gt;&amp;gt; AlwaysNew &amp;gt;&amp;gt; MunqIoC &amp;gt;&amp;gt; Resolve IDB (for petapoco)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;File: Bootstrapper.cs &lt;/strong&gt;used at MVC4 portal section:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;using&lt;/span&gt; System;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Linq;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Text;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Web.Http.Controllers;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; Munq;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; Munq.LifetimeManagers;
&lt;span style="color: green;"&gt;//using StructureMap;&lt;/span&gt;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyDAL.Infrastructures.DBInterfaces;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyDAL.OrM.Petapoco;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyDAL.DataInterfaces;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyDAL.DataConcretes;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyWebServices.Filters;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyWebServices.Selectors;



&lt;span style="color: blue;"&gt;namespace&lt;/span&gt; GovernmentSurveyWebServices.IoC
{
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; Bootstrapper
    {
        &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; ConfigureStructureMap()
        {
            &lt;span style="color: green;"&gt;//ObjectFactory.Initialize(x =&amp;gt; x.AddRegistry&amp;lt;PetaPocoRegistry&amp;gt;());&lt;/span&gt;
            &lt;span style="color: green;"&gt;//ObjectFactory.Initialize(x =&amp;gt; x.AddRegistry&amp;lt;IntegrationTestingRegistry&amp;gt;()); &lt;/span&gt;
        }

        &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; IocContainer ConfigureMunqAlwaysNewLifeTime()
        {
            &lt;span style="color: blue;"&gt;var&lt;/span&gt; IoCAlwaysNew = &lt;span style="color: blue;"&gt;new&lt;/span&gt; IocContainer();
            &lt;span style="color: green;"&gt;//Lifetime is always new for DB context to avoid lifetime mismatch. CLR &lt;/span&gt;
            &lt;span style="color: green;"&gt;//create object will take around 0.0000006 sec. Refer to Rob Connery's and Ayende discussion&lt;/span&gt;
            &lt;span style="color: green;"&gt;//during code review for MVC1 StoreFront videos. I thinks video session no. 15&lt;/span&gt; when they are dicussing using structureMap

            ILifetimeManager lifetime = &lt;span style="color: blue;"&gt;new&lt;/span&gt; Munq.LifetimeManagers.AlwaysNewLifetime();
            IoCAlwaysNew.UsesDefaultLifetimeManagerOf(lifetime);
            IoCAlwaysNew.Register&amp;lt;IDatabase&amp;gt;(x =&amp;gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; Database(&lt;span style="color: #a31515;"&gt;"your_db_name"&lt;/span&gt;));

            &lt;span style="color: blue;"&gt;return&lt;/span&gt; IoCAlwaysNew;
        }

        &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; IocContainer ConfigureMunqContainerLifeTime()
        {
            &lt;span style="color: blue;"&gt;var&lt;/span&gt; DBContainer = ConfigureMunqAlwaysNewLifeTime();
            ILifetimeManager lifetime = &lt;span style="color: blue;"&gt;new&lt;/span&gt; Munq.LifetimeManagers.ContainerLifetime();
            &lt;span style="color: blue;"&gt;var&lt;/span&gt; IoCContainerLifetime = &lt;span style="color: blue;"&gt;new&lt;/span&gt; IocContainer();
            IoCContainerLifetime.UsesDefaultLifetimeManagerOf(lifetime);

            IoCContainerLifetime.Register&amp;lt;IWriteDemographics&amp;gt;
                (x =&amp;gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; WriteDemographicsV1(DBContainer.Resolve&amp;lt;IDatabase&amp;gt;()));
            IoCContainerLifetime.Register&amp;lt;IReadDemographics&amp;gt;
                (x =&amp;gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; ReadDemographicsV1(DBContainer.Resolve&amp;lt;IDatabase&amp;gt;()));

            IoCContainerLifetime.Register&amp;lt;IWriteSurveysMOH&amp;gt;
                (x =&amp;gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; WriteSurveysMOH(DBContainer.Resolve&amp;lt;IDatabase&amp;gt;()));
            IoCContainerLifetime.Register&amp;lt;IReadSurveysMOH&amp;gt;
                (x =&amp;gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; ReadSurveysMOH(DBContainer.Resolve&amp;lt;IDatabase&amp;gt;()));


            &lt;span style="color: blue;"&gt;return&lt;/span&gt; IoCContainerLifetime;

        }

        &lt;span style="color: green;"&gt;//move to Application_Start at Global.asax.cs&lt;/span&gt;
        &lt;span style="color: green;"&gt;//public static IocContainer ConfigureMunqApplicationStart()&lt;/span&gt;
        &lt;span style="color: green;"&gt;//{&lt;/span&gt;
        &lt;span style="color: green;"&gt;//    ILifetimeManager lifetime = new Munq.LifetimeManagers.ContainerLifetime();&lt;/span&gt;
        &lt;span style="color: green;"&gt;//    var IoCContainerAppStart = new IocContainer();&lt;/span&gt;
        &lt;span style="color: green;"&gt;//    IoCContainerAppStart.UsesDefaultLifetimeManagerOf(lifetime);&lt;/span&gt;

        &lt;span style="color: green;"&gt;//    IoCContainerAppStart.Register&amp;lt;IHttpActionSelector&amp;gt;(x =&amp;gt; new CorsPreflightActionSelector());&lt;/span&gt;
        &lt;span style="color: green;"&gt;//    return IoCContainerAppStart;&lt;/span&gt;
        &lt;span style="color: green;"&gt;//}&lt;/span&gt;
        
    }
}&lt;br /&gt;&lt;br /&gt;At controller level:&lt;br /&gt;&lt;br /&gt;&lt;div style="color: black; background-color: white;"&gt;&lt;pre&gt;&lt;span style="color: blue;"&gt;using&lt;/span&gt; System;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Globalization;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Linq;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Net;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Net.Http;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Net.Http.Formatting;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Web.Http;

&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Web.Http.Controllers; &lt;span style="color: green;"&gt;//add this for CORS&lt;/span&gt;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyDAL.DataInterfaces;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyDAL.Models;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyDAL.BizModels.Listings;

&lt;span style="color: blue;"&gt;using&lt;/span&gt; Munq;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyWebServices.IoC;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyWebServices.Filters;&lt;span style="color: green;"&gt;//add this for CORS&lt;/span&gt;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyWebServices.Selectors;&lt;span style="color: green;"&gt;//add this for CORS beta method&lt;/span&gt;

&lt;span style="color: blue;"&gt;namespace&lt;/span&gt; GovernmentSurveyWebServices.Controllers
{
    [HttpControllerConfiguration(HttpActionSelector = &lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(CorsActionSelector))] &lt;span style="color: green;"&gt;//add this for CORS beta method&lt;/span&gt;
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; SurveysMOHController : ApiController
    {

        IReadSurveysMOH _contextRead;
        IWriteSurveysMOH _contextWrite;

        &lt;span style="color: blue;"&gt;public&lt;/span&gt; SurveysMOHController()
        {
            IocContainer _ioc = Bootstrapper.ConfigureMunqContainerLifeTime();
            _contextRead = _ioc.Resolve&amp;lt;IReadSurveysMOH&amp;gt;();
            _contextWrite = _ioc.Resolve&amp;lt;IWriteSurveysMOH&amp;gt;();
        }

        [AcceptVerbs(&lt;span style="color: #a31515;"&gt;"GET"&lt;/span&gt;, &lt;span style="color: #a31515;"&gt;"HEAD"&lt;/span&gt;)]
        [EnableCors]
        &lt;span style="color: blue;"&gt;public&lt;/span&gt; IQueryable&amp;lt;SurveyType&amp;gt; SurveyTypes()
        {
            &lt;span style="color: blue;"&gt;try&lt;/span&gt;
            {
                &lt;span style="color: blue;"&gt;var&lt;/span&gt; _results = _contextRead.GetAllSurveyTypes();
                &lt;span style="color: blue;"&gt;return&lt;/span&gt; _results;
            }
            &lt;span style="color: blue;"&gt;catch&lt;/span&gt; (Exception)
            {
                &lt;span style="color: blue;"&gt;var&lt;/span&gt; exceptionResponse = &lt;span style="color: blue;"&gt;new&lt;/span&gt; HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = &lt;span style="color: blue;"&gt;new&lt;/span&gt; StringContent(&lt;span style="color: #a31515;"&gt;"Internal Server Error."&lt;/span&gt;)
                };

                &lt;span style="color: blue;"&gt;throw&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; HttpResponseException(exceptionResponse);
            }
        }
......&lt;br /&gt;&lt;br /&gt;At Object repository:&lt;br /&gt;&lt;br /&gt;&lt;div style="color: black; background-color: white;"&gt;&lt;pre&gt;&lt;span style="color: blue;"&gt;using&lt;/span&gt; System;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Linq;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Text;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyDAL.Models;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyDAL.BizModels.Listings;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyDAL.DataInterfaces;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyDAL.Infrastructures.DBInterfaces;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyDAL.OrM.Petapoco;

&lt;span style="color: blue;"&gt;namespace&lt;/span&gt; GovernmentSurveyDAL.DataConcretes
{
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; ReadSurveysMOH : IReadSurveysMOH
    {
        &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;readonly&lt;/span&gt; IDatabase _db;
        &lt;span style="color: blue;"&gt;public&lt;/span&gt; ReadSurveysMOH(IDatabase dataContext)
        {
            _db = dataContext;
        }

        &lt;span style="color: blue;"&gt;#region&lt;/span&gt; survey type
        &lt;span style="color: blue;"&gt;public&lt;/span&gt; IQueryable&amp;lt;SurveyType&amp;gt; GetAllSurveyTypes()
        {
            &lt;span style="color: blue;"&gt;var&lt;/span&gt; results = _db.Fetch&amp;lt;SurveyType&amp;gt;().AsQueryable();
            &lt;span style="color: blue;"&gt;return&lt;/span&gt; results;
        }

        &lt;span style="color: blue;"&gt;public&lt;/span&gt; SurveyType GetSurveyTypeById(&lt;span style="color: blue;"&gt;int&lt;/span&gt; surveyTypeId)
        {
            &lt;span style="color: blue;"&gt;var&lt;/span&gt; result = _db.First&amp;lt;SurveyType&amp;gt;(&lt;span style="color: #a31515;"&gt;"SELECT * FROM SurveyType WHERE Id=@0"&lt;/span&gt;, surveyTypeId);
            &lt;span style="color: blue;"&gt;return&lt;/span&gt; result;
        }
        &lt;span style="color: blue;"&gt;#endregion&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
........&lt;br /&gt;&lt;br /&gt;&amp;nbsp;At Interface Level:&lt;br /&gt;&lt;br /&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;using&lt;/span&gt; System;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Linq;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Text;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyDAL.Models;
&lt;span style="color: blue;"&gt;using&lt;/span&gt; GovernmentSurveyDAL.BizModels.Listings;

&lt;span style="color: blue;"&gt;namespace&lt;/span&gt; GovernmentSurveyDAL.DataInterfaces
{
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;interface&lt;/span&gt; IReadSurveysMOH
    {
........

        &lt;span style="color: green;"&gt;//surveys types&lt;/span&gt;
        IQueryable&amp;lt;SurveyType&amp;gt; GetAllSurveyTypes();
        SurveyType GetSurveyTypeById(&lt;span style="color: blue;"&gt;int&lt;/span&gt; surveyTypeId);

       
.......

        &lt;span style="color: blue;"&gt;bool&lt;/span&gt; IfExist&amp;lt;T&amp;gt;(&lt;span style="color: blue;"&gt;int&lt;/span&gt; idTocheck);
        &lt;span style="color: blue;"&gt;bool&lt;/span&gt; IfExist&amp;lt;T&amp;gt;(&lt;span style="color: blue;"&gt;string&lt;/span&gt; idTocheck);
        
    }
&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is not the best solution but I managed to make it work smoothly without worrying about impedance mismatch. &lt;br /&gt;My controller is quite clean and my views are both at portal and mobile devices. Using shared hosting... Munq is really fast. Hope&lt;br /&gt;the above could help and remember Singleton should be used after really sure about object creation and Http propagation. &lt;br /&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/pre&gt;
&lt;/div&gt;
&amp;nbsp;&lt;br /&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;</description><author>zakizakaria69</author><pubDate>Thu, 09 Aug 2012 07:47:52 GMT</pubDate><guid isPermaLink="false">New Post: Requestlifetime issue 20120809074752A</guid></item></channel></rss>