Re: StructureMap Error 202/ASP.NET MVC4

101 views
Skip to first unread message

Jeremy Miller

unread,
Jul 15, 2013, 5:10:04 PM7/15/13
to structure...@googlegroups.com
I'm sorry Norman, but I'm just not knowledgeable enough about MVC to help you here.  Hopefully you've found help somewhere else by now.

The root of the problem is that StructureMap is trying to use a constructor with the DataContext.  You might just need to have the EF pieces wired up in StructureMap.

- Jeremy

On Saturday, May 11, 2013 3:04:15 PM UTC-5, nlk10010 wrote:

I have a well-functioning VS 2010/ASP.NET MVC3 (Linq, Entity Framework) application that I'm upgrading to VS2012/ASP.NET MVC4. I created a new ASP.NET MVC4 project, clean, from the Template, then added all the references (including StructureMap) through NuGet,

Certain of my controllers access their data through a repository; e.g.

private ICustomerRepository _cr;

        public CustomerController()
        {
            this._cr = new CustomerRepository(MyDataProvider.DB);
        }

        public CustomerController(ICustomerRepository customerRepository)
        {
            this._cr = customerRepository;
        }

The repository was handled fine through IoC and StructureMap in MVC3. MyDataProvider.DB is an instance of MyDataContext.

However, when I debug my app I find that any time I try to instantiate any of these controllers (i.e. the ones using the CustomerRepository), an exception is thrown "ServiceLocatorImpIBase.cs not found, Activation error occurred while trying to get instance of type Customer Controller, key "" ". The Detail is: "StructureMap Exception Code 202, No Default Instance found for PlugIn Family MyDataContext........".

I've looked at all the articles I can find on this kind of problem; e.g. Phil Haack, Configuring MVC with StructureMap, Brett Allred. In particular the last seems to be precisely my problem (I'm not sure, but I'd like to test it). Problem is, when I try to implement his code VS won't compile it, complaining that "ServiceResolverAdapter" doesn't implement Dispose() or BeginScope(). Frankly, I don't know if this will correct things either but I can't seem to get beyond this brick wall.

Any ideas about this would be gratefully received, thanks in advance.


Norman
Reply all
Reply to author
Forward
0 new messages