Showing posts with label Dipendency Injection(DI). Show all posts
Showing posts with label Dipendency Injection(DI). Show all posts

Tuesday, 10 July 2012

Could not load type 'System.Web.Http.Dependencies.IDependencyScope'

I am working on one Asp.Net WebApi project along with 5 members in my team. We are using
Asp.net MVC4  Beta for the WebApi project. Everything is working for me fine. Suddenly one day I got the latest version of code from TFS and try to run the application. The solution build succeed, but the application throwing the following exception.
Could not load type 'System.Web.Http.Dependencies.IDependencyScope' from assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
The same application is running in my other teammates. I researched around one day, but did not found any solution that why this dll is not loading run time even though the dll is present in the bin folder.  One of my team mate told that Asp.Net MVC4 is updated from beta to release version. I updated that in my system then the application is working fine. There was mismatch in the team communicatin about this updatation I lost my one day. If any one get this exception try to update the WebApi to release candidate.

Friday, 18 May 2012

structuremap 2.6 IncludeConfigurationFromConfigFile=true not working

When we are using structuremap 2.6.x  and adding structuremap configuration in the app.config/web.config. To  include configuration every one set the property IncludeConfigurationFromConfigFile=true. It is not working and seems to be not implemented. But when we are refering same app.config with AddConfigurationFromXmlFile(configfilepath) then it is working fine. when we are using app.config the file name of configuration is changed after the solution build. To include that configuration file find the solution below.
To get the name and path of configuration file as follows
var configName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; 
The example method and usage as follows:

 private static IContainer InitiazlizeFromAppConfigOrWebConfig()
 {
   var configName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; 
    return new Container(x =>
    {
     x.AddConfigurationFromXmlFile(configName);
      //x.IncludeConfigurationFromConfigFile = true; //seems not imeplemented
    });
}

Wednesday, 16 May 2012

ObjectFactory Vs Container StructureMap

ObjectFactory is a static gateway for an instance of container. If you only ever want one instance of a container, and want a simple static way to get at it, use ObjectFactory. You must Initialize the ObjectFactory, and then retrieve your instances via ObjectFactory.

 Alternatively, if you want to manage the lifetime of the container yourself, you can create an instance of Container, passing an initialization expression to the constructor. You then retrieve instances from the variable you declared to store the Container.