<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/rss.xsl"?><rss version="2.0"><channel><title>simpleinjector Discussions Rss Feed</title><link>http://simpleinjector.codeplex.com/Thread/List.aspx</link><description>simpleinjector Discussions Rss Description</description><item><title>New Post: LifetimeScoping error in WebApi self hosted app</title><link>http://simpleinjector.codeplex.com/discussions/444188</link><description>&lt;div style="line-height: normal;"&gt;Hey. I read these (&lt;a href="https://simpleinjector.codeplex.com/wikipage?title=Web%20API%20Integration&amp;amp;referringTitle=Integration%20Guide" rel="nofollow"&gt;+&lt;/a&gt; , &lt;a href="https://simpleinjector.codeplex.com/wikipage?title=Self%20Hosted%20Web%20API%20Integration&amp;amp;referringTitle=Web%20API%20Integration" rel="nofollow"&gt;+&lt;/a&gt; , &lt;a href="https://simpleinjector.codeplex.com/discussions/430603" rel="nofollow"&gt;+&lt;/a&gt; and &lt;a href="http://stackoverflow.com/questions/10955077/simple-injector-inject-same-unitofwork-instance-across-services-of-the-same-gra" rel="nofollow"&gt;+&lt;/a&gt; ) pages, but I connot figure out what should I do.&lt;br /&gt;
I have this simple interface and concrete type:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;public interface IIdentifierGenerator {
    long Generate(Type type);
    long Generate&amp;lt;TType&amp;gt;(TType type);
}
public HiloIdentifierGenerator : IIdentifierGenerator { /* implementation... */ }&lt;/code&gt;&lt;/pre&gt;

I create this &lt;strong&gt;DependencyResolver&lt;/strong&gt;:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;public class SelfHostedSimpleInjectorWebApiDependencyResolver : IDependencyResolver {

        private readonly Container _container;
        private readonly LifetimeScope _lifetimeScope;

        public SelfHostedSimpleInjectorWebApiDependencyResolver(
            Container container)
            : this(container, false) {
        }

        private SelfHostedSimpleInjectorWebApiDependencyResolver(
            Container container, bool createScope) {
            _container = container;

            if (createScope) {
                _lifetimeScope = container.BeginLifetimeScope();
            }
        }

        public IDependencyScope BeginScope() {
            return new SelfHostedSimpleInjectorWebApiDependencyResolver(
                _container, true);
        }

        public object GetService(Type serviceType) {
            return ((IServiceProvider)_container)
                .GetService(serviceType);
        }

        public IEnumerable&amp;lt;object&amp;gt; GetServices(Type serviceType) {
            return _container.GetAllInstances(serviceType);
        }

        public void Dispose() {
            if (_lifetimeScope != null) {
                _lifetimeScope.Dispose();
            }
        }
    }&lt;/code&gt;&lt;/pre&gt;

and I configured my server like this:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;            _config = new HttpSelfHostConfiguration(&amp;quot;http://192.168.1.100:20000&amp;quot;);
            _config.Routes.MapHttpRoute(
                &amp;quot;API Default&amp;quot;, &amp;quot;api/{controller}/{id}&amp;quot;,
                new { id = RouteParameter.Optional });
            _config.DependencyResolver =
                new SelfHostedSimpleInjectorWebApiDependencyResolver(
                    IoC.Wrapper.GetService&amp;lt;Container&amp;gt;());
            _server = new HttpSelfHostServer(_config);
            /* etc. */&lt;/code&gt;&lt;/pre&gt;

And this is my controller:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;    public class IdentifierController : ApiController {

        private readonly IIdentifierGenerator _identifierGenerator;

        public IdentifierController(IIdentifierGenerator identifierGenerator) {
            _identifierGenerator = identifierGenerator;
        }

        public long Get(string id) {
            var type = Type.GetType(id, false, true);
            return type == null ? -1 : _identifierGenerator.GetIdentifier(type);
        }
    }&lt;/code&gt;&lt;/pre&gt;

Now, when I call the action method, I get this error:&lt;br /&gt;
&lt;blockquote&gt;
It is not safe to use a LifetimeScope instance across threads. Make sure the complete operation that the lifetime scope surrounds gets executed within the same thread and make sure that the LifetimeScope instance gets disposed on the same thread as it gets created. Dispose was called on thread with ManagedThreadId 28, but was created on thread with id 29.&lt;br /&gt;
&lt;/blockquote&gt;
Where am I doing wrong? Can you help please?&lt;br /&gt;
&lt;/div&gt;</description><author>kavand</author><pubDate>Sun, 19 May 2013 12:36:08 GMT</pubDate><guid isPermaLink="false">New Post: LifetimeScoping error in WebApi self hosted app 20130519123608P</guid></item><item><title>New Post: Register an Interface wich implementation's constructor has arguments</title><link>http://simpleinjector.codeplex.com/discussions/443987</link><description>&lt;div style="line-height: normal;"&gt;Thank you for your answer. I'll try to avoid delegating the creation to the DI container.&lt;br /&gt;
&lt;/div&gt;</description><author>The_Chaoz</author><pubDate>Sun, 19 May 2013 07:00:45 GMT</pubDate><guid isPermaLink="false">New Post: Register an Interface wich implementation's constructor has arguments 20130519070045A</guid></item><item><title>New Post: SimpleInjector Prism Bootstrapper</title><link>http://simpleinjector.codeplex.com/discussions/444128</link><description>&lt;div style="line-height: normal;"&gt;Hi all,&lt;br /&gt;
&lt;br /&gt;
So a colleague directed me towards SimpleInjector after viewing the stats &lt;a href="http://www.palmmedia.de/Blog/2011/8/30/ioc-container-benchmark-performance-comparison" rel="nofollow"&gt;here&lt;/a&gt;. He felt it had the right level of features for his MVC project, whilst being among the fastest around.&lt;br /&gt;
&lt;br /&gt;
I'm starting a new prism app (still feeling my way around the basics of prism/MVVM to be honest), but I was wondering if there is a SI bootstrapper around anywhere for Prism?&lt;br /&gt;
&lt;br /&gt;
If not, can someone point me in the direction of where I can see how the bootstrappers are constructed (i.e. what I'd need to do to roll my own).&lt;br /&gt;
&lt;br /&gt;
Thanks&lt;br /&gt;
Fergal&lt;br /&gt;
&lt;/div&gt;</description><author>ObsidianPhoenix</author><pubDate>Sat, 18 May 2013 10:55:12 GMT</pubDate><guid isPermaLink="false">New Post: SimpleInjector Prism Bootstrapper 20130518105512A</guid></item><item><title>New Post: Register an Interface wich implementation's constructor has arguments</title><link>http://simpleinjector.codeplex.com/discussions/443987</link><description>&lt;div style="line-height: normal;"&gt;View Models are created by your presentation layer (most often your controller, presenter, page, or whatever your pattern you're using) and are filled with data from the model and possibly other sources. Since this View Model class (this data package) is created using (almost) all run-time values, in shouldn't delegate the creation to your DI container. Further more, in general you're not interested to abstract the View Model from your View or Controller, because it is simply a data package.&lt;br /&gt;
&lt;br /&gt;
If you still try this, you will find out very soon that this gets really awkward, and this holds not only when working with Simple Injector, but for all DI frameworks.&lt;br /&gt;
&lt;br /&gt;
But when we ignore the fact that you're dealing with a view model, you can register types with a string parameter as follows (excuse my C#):&lt;br /&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
container.Register&amp;lt;ISomeService&amp;gt;(() =&amp;gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; SomeServiceImpl(&lt;span style="color:#A31515;"&gt;&amp;quot;somePath&amp;quot;&lt;/span&gt;));
&lt;/pre&gt;&lt;/div&gt;And when you need to supply a runtime value, you can register &lt;a href="https://simpleinjector.codeplex.com/wikipage?title=How-to#Register-Factory-Delegates" rel="nofollow"&gt;a factory&lt;/a&gt;  or register a Func&amp;lt;T&amp;gt; delegate as follows:&lt;br /&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
container.RegisterSingle&amp;lt;Func&amp;lt;&lt;span style="color:Blue;"&gt;string&lt;/span&gt;, ISomeService&amp;gt;&amp;gt;(
    path =&amp;gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; SomeServiceImpl(path));
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</description><author>dot_NET_Junkie</author><pubDate>Fri, 17 May 2013 08:37:58 GMT</pubDate><guid isPermaLink="false">New Post: Register an Interface wich implementation's constructor has arguments 20130517083758A</guid></item><item><title>New Post: Register an Interface wich implementation's constructor has arguments</title><link>http://simpleinjector.codeplex.com/discussions/443987</link><description>&lt;div style="line-height: normal;"&gt;Well I read the documentation but I couldn't find how to do this.&lt;br /&gt;
I've for example a class called &amp;quot;DocumentViewModel&amp;quot; wich constructor is something like:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;Public Sub New(ByVal filepath As String)
    _filepath = New FilePath(filepath)
    //more code...
End Sub&lt;/code&gt;&lt;/pre&gt;

How should I register this? And how should I implement this?&lt;br /&gt;
&lt;br /&gt;
Thanks in advance&lt;br /&gt;
&lt;/div&gt;</description><author>The_Chaoz</author><pubDate>Fri, 17 May 2013 01:51:38 GMT</pubDate><guid isPermaLink="false">New Post: Register an Interface wich implementation's constructor has arguments 20130517015138A</guid></item><item><title>New Post: Can Simple Injector support Web API and MVC Controllers simultaneously?</title><link>https://simpleinjector.codeplex.com/discussions/443293</link><description>&lt;div style="line-height: normal;"&gt;Thanks! - Adding the additional SetResolver call did the trick! Here is my final code:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;  public static class SimpleInjectorInitializer
    {
        /// &amp;lt;summary&amp;gt;Initialize the container and register it as MVC3 Dependency Resolver.&amp;lt;/summary&amp;gt;
        public static void Initialize()
        {
            var container = new Container();

            // register Web API controllers (important!)
            var controllerTypes =
                from type in Assembly.GetExecutingAssembly().GetExportedTypes()
                where typeof(IHttpController).IsAssignableFrom(type) // (typeof(IHttpController).IsAssignableFrom(type) || (typeof(IController).IsAssignableFrom(type) &amp;amp;&amp;amp; type.Name != &amp;quot;HelpController&amp;quot;))
                where !type.IsAbstract
                where !type.IsGenericTypeDefinition
                where type.Name.EndsWith(&amp;quot;Controller&amp;quot;, StringComparison.Ordinal)
                select type;

            foreach (var controllerType in controllerTypes)
            {
                container.Register(controllerType);
            }

            // Register your types, for instance:
            container.Register&amp;lt;IRepository, Repository&amp;gt;();

            // register MVC controllers (This is an extension method from the integration package).
            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            // register MVC attributes (This is an extension method from the integration package as well).
            container.RegisterMvcAttributeFilterProvider();

            // Verify the container configuration
            container.Verify();

            System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);

            System.Web.Mvc.DependencyResolver.SetResolver(
                new SimpleInjector.Integration.Web.Mvc.SimpleInjectorDependencyResolver(container));

        }
    }&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;</description><author>Sergeir</author><pubDate>Mon, 13 May 2013 20:17:07 GMT</pubDate><guid isPermaLink="false">New Post: Can Simple Injector support Web API and MVC Controllers simultaneously? 20130513081707P</guid></item><item><title>New Post: WebActivator Initialization vs. Global.asax app_start configuration paradigm</title><link>https://simpleinjector.codeplex.com/discussions/443150</link><description>&lt;div style="line-height: normal;"&gt;An assembly is not the same as an NuGet package. In fact, the MVC Quick Start Package itself, does not contain an assembly. It contains a reference to three other NuGet packages (two Simple Injector packages and the WebActivator package) and one content file. &lt;br /&gt;
&lt;br /&gt;
Again, none of the dlls (assemblies) provided by Simple Injector reference the WebActivator. To integrate Simple Injector with MVC you don't need the MVC Quick Start package. The Quick Start is really just built to bootstrap everything together. If you don't want to use WebActivator, just deinstall the MVC Quick Start package and use the &lt;strong&gt;SimpleInjector.Integration.Web.Mvc&lt;/strong&gt; NuGet package directly. The assembly in that package depends on SimpleInjector.dll and SimpleInjector.Integration.Web.dll and those are located in the NuGet packages with the same name.&lt;br /&gt;
&lt;br /&gt;
SimpleInjector.Integration.Web.dll however, does not have a dependency on WebActivator. It only takes (besides SimpleInjector.dll) a dependency Microsoft.Web.Infrastructure.dll, which is part of the .NET framework.&lt;br /&gt;
&lt;/div&gt;</description><author>dot_NET_Junkie</author><pubDate>Mon, 13 May 2013 18:21:13 GMT</pubDate><guid isPermaLink="false">New Post: WebActivator Initialization vs. Global.asax app_start configuration paradigm 20130513062113P</guid></item><item><title>New Post: WebActivator Initialization vs. Global.asax app_start configuration paradigm</title><link>http://simpleinjector.codeplex.com/discussions/443150</link><description>&lt;div style="line-height: normal;"&gt;The statement &amp;quot;none of the Simple Injector assemblies in fact have a dependency on WebActivator&amp;quot; seems to be incorrect.  I just tried to uninstall WebActivator after uninstalling the Quick Start NuGet package and get the following:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Unable to uninstall 'WebActivator 1.4.4' because 'SimpleInjector.Integration.Web 2.2.3' depend(s) on it.&amp;quot;&lt;br /&gt;
&lt;/div&gt;</description><author>omegaluz</author><pubDate>Mon, 13 May 2013 15:54:28 GMT</pubDate><guid isPermaLink="false">New Post: WebActivator Initialization vs. Global.asax app_start configuration paradigm 20130513035428P</guid></item><item><title>New Post: Scenario questions about SI</title><link>http://simpleinjector.codeplex.com/discussions/443157</link><description>&lt;div style="line-height: normal;"&gt;That was all very helpful, thanks!&lt;br /&gt;
&lt;/div&gt;</description><author>androticus</author><pubDate>Sun, 12 May 2013 16:05:13 GMT</pubDate><guid isPermaLink="false">New Post: Scenario questions about SI 20130512040513P</guid></item><item><title>New Post: Scenario questions about SI</title><link>https://simpleinjector.codeplex.com/discussions/443157</link><description>&lt;div style="line-height: normal;"&gt;Simple Injector does not allow resolving Lifetime Scoped instances outside the context of a scope. This design is deliberate. One of the earlier versions of the framework in fact behaved differently and followed the design of Autofac and other containers to return a singleton instance in the case there was no scope.&lt;br /&gt;
&lt;br /&gt;
This design however proved to be bad, since returning a singleton is almost always a bad idea, since components are often registered with Lifetime Scope because they are not thread-safe and should not be reused. A great example of this is the Unit of Work pattern that Entity Framework implements with its DbContext and ObjectContext classes. We saw users spinning off background threads and forget to start a new scope, which caused their Unit of Work class to be shared over multiple threads, which lead to errors in production.&lt;br /&gt;
&lt;br /&gt;
Because of this we decided to disallow this by default. Perhaps your case is different and it is okay to return a default instance. If you really want to do this, you can enable this by using a Hybrid lifestyle, as follows:&lt;br /&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; scopedLifestyleWithSingletonFallback = Lifestyle.CreateHybrid(
    () =&amp;gt; container.GetCurrentLifetimeScope() != &lt;span style="color:Blue;"&gt;null&lt;/span&gt;,
    &lt;span style="color:Blue;"&gt;new&lt;/span&gt; LifetimeScopeLifestyle(),
    Lifestyle.Singleton); &lt;span style="color:Green;"&gt;// the fallback lifestyle&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;But please take a look carefully at your design if this really is what you need and if it is possible for a programmer to make a mistake in such way that things accidentally are returned as singleton, while it should have been scoped. Since you are running a Windows Service that spins of new threads to do its work, it seems very unlikely that any code should even run outside the context of a lifetime scope.&lt;br /&gt;
&lt;br /&gt;
When you spin of a background thread and have any components registered as Lifetime Scope, you will have to wrap the execution with a lifetime scope. You will have to start the scope before requesting the root object, for instance:&lt;br /&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
Task.Factory.StartNew(() =&amp;gt;
{
    &lt;span style="color:Blue;"&gt;using&lt;/span&gt; (container.BeginLifetimeScope())
    {
         &lt;span style="color:Green;"&gt;// resolve root object&lt;/span&gt;
         &lt;span style="color:Blue;"&gt;var&lt;/span&gt; service = container.GetInstance&amp;lt;ISomeService&amp;gt;();
         service.Do();
    }
}
&lt;/pre&gt;&lt;/div&gt;This code should be part of your application's &lt;a href="http://blog.ploeh.dk/2011/07/28/CompositionRoot/" rel="nofollow"&gt;Composition Root&lt;/a&gt; and not of any application code. This prevents the application to know anything about it. Of course the code cannot run without outside the context of a lifetime scope, but this is quite obvious. The fact that the consumer should now as little as possible doesn't mean it should be able to work in any case. Not starting a scope is a misconfiguration and you'd rather see the application fail than silently continue in error. Neither would you want the application to continue when one of your registrations is missing. You should always fail fast.&lt;br /&gt;
&lt;blockquote&gt;
I want the middleware to use the logging object that is for that specific service.&lt;br /&gt;
&lt;/blockquote&gt;
This seems more like &lt;a href="https://simpleinjector.codeplex.com/wikipage?title=Advanced-scenarios#Context-Based-Injection" rel="nofollow"&gt;Context Based Injection&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Lifetime Scoping in Simple Injector differs from the concept of Child Containers that frameworks such as Unity use. A child container allows you to do special registrations in that child container. Simple Injector does use this approach, since it is impossible to both allow creating child containers with new registrations and having good performance at the same time. If I understand correctly you want to register a new instance at the beginning of the thread and reuse that same instance for the duration of that scope. There are several ways to do this. Here is an idea:&lt;br /&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Registration&lt;/span&gt;
container.RegisterLifetimeScope&amp;lt;LoggerContext&amp;gt;();

container.RegisterLifetimeScope&amp;lt;ILogger&amp;gt;(
    () =&amp;gt; container.GetInstance&amp;lt;LoggerContext&amp;gt;().Logger ?? 
        NullLogger.Instance);

&lt;span style="color:Green;"&gt;// This class is unknown to the application, only known in &lt;/span&gt;
&lt;span style="color:Green;"&gt;// the composition root.&lt;/span&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; LoggerContext
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; ILogger Logger { &lt;span style="color:Blue;"&gt;get&lt;/span&gt;; &lt;span style="color:Blue;"&gt;set&lt;/span&gt;; }
}

&lt;span style="color:Green;"&gt;// Part of the Compostion root that starts a use case:&lt;/span&gt;
Task.Factory.StartNew(() =&amp;gt;
{
    &lt;span style="color:Blue;"&gt;using&lt;/span&gt; (container.BeginLifetimeScope())
    {
        &lt;span style="color:Green;"&gt;// Set the logger to be used during this scope.&lt;/span&gt;
        container.GetInstance&amp;lt;LoggerContext&amp;gt;().Logger =
            &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Logger(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(ISomeService), &lt;span style="color:#A31515;"&gt;&amp;quot;special stuff&amp;quot;&lt;/span&gt;);
    
         &lt;span style="color:Green;"&gt;// resolve root object&lt;/span&gt;
         &lt;span style="color:Blue;"&gt;var&lt;/span&gt; service = container.GetInstance&amp;lt;ISomeService&amp;gt;();
         service.Do();
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</description><author>dot_NET_Junkie</author><pubDate>Sat, 11 May 2013 10:18:25 GMT</pubDate><guid isPermaLink="false">New Post: Scenario questions about SI 20130511101825A</guid></item><item><title>New Post: Can Simple Injector support Web API and MVC Controllers simultaneously?</title><link>http://simpleinjector.codeplex.com/discussions/443293</link><description>&lt;div style="line-height: normal;"&gt;What is exactly the problem you are having?&lt;br /&gt;
&lt;br /&gt;
Although &lt;a href="http://stackoverflow.com/questions/15494920/what-is-the-difference-between-dependencyresolver-setresolver-and-httpconfigurat/15495934#15495934" rel="nofollow"&gt;not advised&lt;/a&gt;, integrating MVC and Web API in the same project is possible. But since both frameworks have their own API for dependency resolution, you will have to make sure that you register both the MVC DependencyResolver and the Web API DependencyResolver, like this:&lt;br /&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver =
    &lt;span style="color:Blue;"&gt;new&lt;/span&gt; SimpleInjectorWebApiDependencyResolver(container);
        
System.Web.Mvc.DependencyResolver.SetResolver(
    &lt;span style="color:Blue;"&gt;new&lt;/span&gt; SimpleInjector.Integration.Web.Mvc.SimpleInjectorDependencyResolver(container));
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</description><author>dot_NET_Junkie</author><pubDate>Sat, 11 May 2013 09:35:43 GMT</pubDate><guid isPermaLink="false">New Post: Can Simple Injector support Web API and MVC Controllers simultaneously? 20130511093543A</guid></item><item><title>New Post: Scenario questions about SI</title><link>http://simpleinjector.codeplex.com/discussions/443157</link><description>&lt;div style="line-height: normal;"&gt;Here is code for the Scoped Instance Scenario (I will provide the other scenario in another message). I think it is easiest with the concrete use- case, which is for a logging interface. We have a lot of code that is in windows services, where the code provides several different services running on different threads using different loggers. When I make a call to the middleware in a scoped instance from one of those threads, I want the middleware to use the logging object that is for that specific service. The example below is for some middleware service ISomeService that takes a ILogger which I want to supply. I want to set that instance of the Logger in the scope so that all DI resolutions within that scope will use that logger instance.&lt;br /&gt;
&lt;br /&gt;
//ctor for SomeService : ISomeService&lt;br /&gt;
&lt;br /&gt;
public SomeService(ILogger logger) {&lt;br /&gt;
...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// sample scenario:&lt;br /&gt;
Container container = new Container();&lt;br /&gt;
&lt;br /&gt;
// global registrations not shown&lt;br /&gt;
container.Register&amp;lt;ISomeService, SomeService&amp;gt;(new LifestyleScoped());&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
using (container.BeginLifetimeScope())&lt;br /&gt;
{&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;container.RegisterSingle&amp;lt;ILogger&amp;gt;(anExistingLoggerInstance); // THIS IS WHAT I WANT TO DO
&lt;/code&gt;&lt;/pre&gt;

...&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;//
ISomeService svc = container.GetInstance&amp;lt;ISomeService &amp;gt;(); // SHOULD GET CONSTRUCTED WITH THE INSTANCE I SET
&lt;/code&gt;&lt;/pre&gt;

}&lt;br /&gt;
&lt;/div&gt;</description><author>androticus</author><pubDate>Fri, 10 May 2013 21:34:45 GMT</pubDate><guid isPermaLink="false">New Post: Scenario questions about SI 20130510093445P</guid></item><item><title>New Post: Can Simple Injector support Web API and MVC Controllers simultaneously?</title><link>http://simpleinjector.codeplex.com/discussions/443293</link><description>&lt;div style="line-height: normal;"&gt;I have an MVC 4 ASP.NET Web API project in which I want to be able to inject a repository into both a MVC controller and an Web API controller. Obviously the project itself supports both types of controllers. I have found documentation on the Simple Injector site which shows how to implement either but not both at once.&lt;br /&gt;
&lt;br /&gt;
I have tried several methods, both of which can be seen in the code below, to no avail:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt; public static class SimpleInjectorInitializer
    {
        /// &amp;lt;summary&amp;gt;Initialize the container and register it as MVC3 Dependency Resolver.&amp;lt;/summary&amp;gt;
        public static void Initialize()
        {
            var container = new Container();

            // register Web API controllers (important!)
            var controllerTypes =
                from type in Assembly.GetExecutingAssembly().GetExportedTypes()
                where typeof(IHttpController).IsAssignableFrom(type) 
                where !type.IsAbstract
                where !type.IsGenericTypeDefinition
                where type.Name.EndsWith(&amp;quot;Controller&amp;quot;, StringComparison.Ordinal)
                select type;

            foreach (var controllerType in controllerTypes)
            {
                container.Register(controllerType);
            }

            // Register your types, for instance:
            container.Register&amp;lt;IRepository, Repository&amp;gt;();

            // register MVC controllers (This is an extension method from the integration package).
            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            // register MVC controllers - second method (This is an extension method from the integration package).
            //var mvcControllerTypes =
            //    from type in SimpleInjectorMvcExtensions.GetControllerTypesToRegister(container, Assembly.GetExecutingAssembly())
            //    where type.Name != &amp;quot;HelpController&amp;quot;
            //    select type;

            //foreach (Type controllerType in mvcControllerTypes)
            //{
            //    container.Register(controllerType);
            //}

            // register MVC attributes (This is an extension method from the integration package as well).
            container.RegisterMvcAttributeFilterProvider();

            // Verify the container configuration
            container.Verify();

            // Register the dependency resolver.
            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);
        }
    }&lt;/code&gt;&lt;/pre&gt;

Here is the SimpleInjectorWebApiDependencyResolver calss taken from the Web API guide:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;public sealed class SimpleInjectorWebApiDependencyResolver
    : IDependencyResolver
{
    private readonly Container container;

    public SimpleInjectorWebApiDependencyResolver(
        Container container)
    {
        this.container = container;
    }

    [DebuggerStepThrough]
    public IDependencyScope BeginScope()
    {
        return this;
    }

    [DebuggerStepThrough]
    public object GetService(Type serviceType)
    {
        return ((IServiceProvider)this.container)
            .GetService(serviceType);
    }

    [DebuggerStepThrough]
    public IEnumerable&amp;lt;object&amp;gt; GetServices(Type serviceType)
    {
        return this.container.GetAllInstances(serviceType);
    }

    [DebuggerStepThrough]
    public void Dispose()
    {
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;a href="http://simpleinjector.codeplex.com/wikipage?title=Web%20API%20Integration" rel="nofollow"&gt;http://simpleinjector.codeplex.com/wikipage?title=Web%20API%20Integration&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://simpleinjector.codeplex.com/wikipage?title=MVC%20Integration" rel="nofollow"&gt;http://simpleinjector.codeplex.com/wikipage?title=MVC%20Integration&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>Sergeir</author><pubDate>Fri, 10 May 2013 20:32:56 GMT</pubDate><guid isPermaLink="false">New Post: Can Simple Injector support Web API and MVC Controllers simultaneously? 20130510083256P</guid></item><item><title>New Post: Scenario questions about SI</title><link>https://simpleinjector.codeplex.com/discussions/443157</link><description>&lt;div style="line-height: normal;"&gt;I'm afraid I don't fully understand your question. Could you please supply me with some more details?&lt;br /&gt;
&lt;blockquote&gt;
You cannot request an instance of a service that has been registered as scoped in a global context.&lt;br /&gt;
&lt;/blockquote&gt;
Are you talking about the Lifetime Scope lifestyle?&lt;br /&gt;
Do you mean that you can't get an instance when you didn't call &lt;code&gt;container.BeginLifetimeScope()&lt;/code&gt;?&lt;br /&gt;
&lt;blockquote&gt;
No apparent way to set a scoped instance&lt;br /&gt;
&lt;/blockquote&gt;
Can you supply me with a concrete (realistic) code example of what you're trying to achieve?&lt;br /&gt;
&lt;/div&gt;</description><author>dot_NET_Junkie</author><pubDate>Thu, 09 May 2013 19:44:33 GMT</pubDate><guid isPermaLink="false">New Post: Scenario questions about SI 20130509074433P</guid></item><item><title>New Post: Scenario questions about SI</title><link>http://simpleinjector.codeplex.com/discussions/443157</link><description>&lt;div style="line-height: normal;"&gt;I have been evaluating Simple Injector, and am having challenges with the following scenarios. I was hoping for some comments:&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;
Scoped registration and instancing are tightly coupled and code must be aware&lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;
You cannot request an instance of a service that has been registered as scoped in a global context. You can only register as scoped, and then need to retrieve as scoped. This seems to violate a principle that the consumer of the service should need to know as little as possible about details like this.&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;
No apparent way to set a scoped instance&lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;
You can manually set instances of globally scoped services, but you can't seem to set instances of scoped services. Example scenarios:&lt;br /&gt;
Outer, global logging instance. Some scoped calls would like to supply a scoped logging object that applies to the calling context.&lt;br /&gt;
Outer, global security credentials object. Calls outside a scope want to use the global security credentials, but some scoped calls provide their own credentials, want to set those.&lt;br /&gt;
&lt;br /&gt;
I realize you can probably do this stuff with various specialized Factory objects and/or instance caches etc., but that seems to defeat the purpose of having a DI framework. Thanks for any feedback!&lt;br /&gt;
&lt;/div&gt;</description><author>androticus</author><pubDate>Thu, 09 May 2013 19:08:16 GMT</pubDate><guid isPermaLink="false">New Post: Scenario questions about SI 20130509070816P</guid></item><item><title>New Post: WebActivator Initialization vs. Global.asax app_start configuration paradigm</title><link>http://simpleinjector.codeplex.com/discussions/443150</link><description>&lt;div style="line-height: normal;"&gt;I must admit that I myself prefer the use of the Global.asax and Application_Start. I do use the Quick Start package, but copy the need configuration to the Global.asax and uninstall the package afterwards.&lt;br /&gt;
&lt;br /&gt;
The use of the WebActivator however, was chosen because this allowed users to get started with Simple Injector just by pulling in the &amp;quot;Simple Injector MVC Integration Quick Start&amp;quot; NuGet package. That package just contains some references to other NuGet packages and one single content file. Adding a content file is a very safe. It prevents having to use tricky Visual Studio integration, which would be needed when an existing Application_Start was altered.  Besides, the addition of one single content file is much easier to grasp for developers, compared to finding out that existing files and code has been altered by some package.&lt;br /&gt;
&lt;br /&gt;
So we went for the safest way that is easiest to explain to developers. If this doesn't suit you (as it doesn't really suit myself either), I advice you to just do what I do: copy that code to the Application_Start and uninstall that package.&lt;br /&gt;
&lt;br /&gt;
Note that that although the Quick Start NuGet package takes a dependency on WebActivator, none of the Simple Injector assemblies in fact have a dependency on WebActivator, so from an architectural perspective there's no problem here. And again, if you don't want to take a dependency on WebActivator, just uninstall the Quick Start NuGet package and you're fine.&lt;br /&gt;
&lt;/div&gt;</description><author>dot_NET_Junkie</author><pubDate>Thu, 09 May 2013 18:57:41 GMT</pubDate><guid isPermaLink="false">New Post: WebActivator Initialization vs. Global.asax app_start configuration paradigm 20130509065741P</guid></item><item><title>New Post: WebActivator Initialization vs. Global.asax app_start configuration paradigm</title><link>http://simpleinjector.codeplex.com/discussions/443150</link><description>&lt;div style="line-height: normal;"&gt;Personally, I like the direction the MVC team has gone in recent years in regards to any application_start code.  Take any of the following for examples:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;protected void Application_Start(Object sender, EventArgs e)
    {

        ViewEngineConfig.Configure();

        AreaRegistration.RegisterAllAreas();

        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

    }
&lt;/code&gt;&lt;/pre&gt;

Using WebActivator goes against this practice and also added another dependency to your project.  Technically, your SimpleInjectorIntializer class can be re-written to use the above paradigm and then remove the need for WebActivator.&lt;br /&gt;
&lt;br /&gt;
What do you think?&lt;br /&gt;
&lt;/div&gt;</description><author>omegaluz</author><pubDate>Thu, 09 May 2013 18:04:18 GMT</pubDate><guid isPermaLink="false">New Post: WebActivator Initialization vs. Global.asax app_start configuration paradigm 20130509060418P</guid></item><item><title>New Post: Simple Injector - Why and where does it loose points?</title><link>http://simpleinjector.codeplex.com/discussions/442920</link><description>&lt;div style="line-height: normal;"&gt;Hi Rod,&lt;br /&gt;
&lt;br /&gt;
Simplicity is one of the main goals of Simple Injector and Simple Injector tries to make it easier for developers to start with Dependency Injection. The feature set of Simple Injector is deliberately stripped and with that it tries to push developres in a certain direction that we feel is best; results in the most maintainable software. This doesn't mean that it is limited in its possibilities, but makes forces you to do a bit more work to get certain behavior. Take for instance making &lt;a href="https://simpleinjector.codeplex.com/wikipage?title=How-to#Resolve-Instances-By-Key" rel="nofollow"&gt;registrations with by name/key&lt;/a&gt; and doing &lt;a href="https://simpleinjector.codeplex.com/wikipage?title=Advanced-scenarios#Property-Injection" rel="nofollow"&gt;implicit property injection&lt;/a&gt;. Both features are possible to implement in Simple Injector, but not supported out-of-the-box (OOTB), because they are abused most of the time and can lead to DI configurations that are hard to verify. We do however provide documentation that explains most scenarios that are not supported OOTB.&lt;br /&gt;
&lt;br /&gt;
Many developers fear the performance of their DI container. In reality most of the time your container´s performance isn´t an issue, but on the other hand, it´s hard to intuitively sense where the performance bottlenecks are and how to solve them. That is something Simple Injector tries to solve. Everything you do OOTB is fast. About as fast as when wiring things by hand (except the constant overhead a call to GetInstance() has, and the one-time performance hit of the initialization phase). This allows developers to stop worrying about the container's performance.&lt;br /&gt;
&lt;br /&gt;
Simple Injector however is is specially designed with a specific type of architecture in mind. Architectures that are based on the SOLID principles, work with generic abstractions, and use decorators to apply crosscutting concerns (take a look &lt;a href="http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=91" rel="nofollow"&gt;here&lt;/a&gt;, &lt;a href="http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=92" rel="nofollow"&gt;here&lt;/a&gt;, and &lt;a href="http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=95" rel="nofollow"&gt;here&lt;/a&gt; for examples of this type of design). Especially the area of using decorators is where other containers lack and where Simple Injector tries to fill a gap. Most containers use a method called interception to apply crosscutting concerns to types, and make it really hard to apply decorators in a way that is maintainable. In our opinion, the use of decorators is much better than using interception, because decorators don´t force you to take a dependency on some interception library, and results in code that is simpler and faster. Simple Injector for instance, makes it very easy to apply (generic) decorators conditionally, based on either a predicate or a generic type constraint.&lt;br /&gt;
&lt;br /&gt;
Unity makes it possible to apply decorators, but when it comes to applying decorators conditionally, this gets really hard in Unity, and will lead to a DI configuration that becomes unmaintanable. Whether or not this is a problem, depends on the size and design of your application, of course.&lt;br /&gt;
&lt;br /&gt;
Of course I´m biased about Simple Injector, and would argue that you can do anything with Simple Injector, but perhaps not OOTB. So things that are supported by Simple Injector OOTB but are in Unity are for instance keyed registration, interception, and handling types with multiple constructors.  Simple Injector on the other hand is very fast and has very good support for decorators.&lt;br /&gt;
&lt;br /&gt;
The choice is up to you.&lt;br /&gt;
&lt;/div&gt;</description><author>dot_NET_Junkie</author><pubDate>Wed, 08 May 2013 10:46:58 GMT</pubDate><guid isPermaLink="false">New Post: Simple Injector - Why and where does it loose points? 20130508104658A</guid></item><item><title>New Post: Simple Injector - Why and where does it loose points?</title><link>http://simpleinjector.codeplex.com/discussions/442920</link><description>&lt;div style="line-height: normal;"&gt;Hi,&lt;br /&gt;
&lt;br /&gt;
I must say I was very impressed with the performance benchmarks I've seen out there regarding Simple Injector as well as the documentation you are providing. &lt;br /&gt;
&lt;br /&gt;
I'm looking into DI frameworks for my company's new product and came across SI. &lt;br /&gt;
&lt;br /&gt;
There is already new developments using Unity for Web applications. The natural way would be to go with Unity. The new product is to be a cloud based multi-threaded application with multiple activations per second so completely different picture.&lt;br /&gt;
&lt;br /&gt;
I have two questions that could help me a lot to decide and influence decisions.&lt;br /&gt;
&lt;br /&gt;
1 - What motivated you on developing such a framework considering the existing ones out there? If it was performance I would like to know about that business case&lt;br /&gt;
2 - What are the concrete feature limitations on this framework? From what I'm seeing it can do almost everything as Unity.&lt;br /&gt;
&lt;br /&gt;
Tnks in advance,&lt;br /&gt;
Rod&lt;br /&gt;
&lt;/div&gt;</description><author>RBoavida</author><pubDate>Wed, 08 May 2013 08:33:56 GMT</pubDate><guid isPermaLink="false">New Post: Simple Injector - Why and where does it loose points? 20130508083356A</guid></item><item><title>New Post: Registering open generic of open generic</title><link>http://simpleinjector.codeplex.com/discussions/442281</link><description>&lt;div style="line-height: normal;"&gt;That did the trick, thanks.  I have other reasons why I need the extra abstraction, but your point is well taken.&lt;br /&gt;
&lt;br /&gt;
Thanks very much for Simple Injector, it is a really great tool!&lt;br /&gt;
&lt;/div&gt;</description><author>timohayes</author><pubDate>Fri, 03 May 2013 19:34:18 GMT</pubDate><guid isPermaLink="false">New Post: Registering open generic of open generic 20130503073418P</guid></item></channel></rss>