Why am I getting InvalidOperationException?

14 views
Skip to first unread message

Gibran Shah

unread,
Jul 11, 2018, 7:29:14 PM7/11/18
to structuremap-users

Hello,

I just created a new MVC application. I'm using it to test out StructureMap.

So far in my Startup.cs file, I have this:

public class Startup
{
...
     public void Configure(...)
     {
     ...
            var container = new StructureMap.Container(c =>
            {
                c.For<IService>().Use<Service>();
            });
     }
}

And in my HomeController, I have this:

public class HomeController
{
     private IService _service;

     public HomeController(IService service)
     {
          _service = service;
     }
.....
}

But when I run it, I get an InvalidOperationException. Can anyone tell me what I'm doing wrong? Thanks.


Gibran

Callen Barton

unread,
Jul 11, 2018, 7:58:42 PM7/11/18
to structuremap-users
Are you using Asp.Net Core?

Gibran Shah

unread,
Jul 12, 2018, 10:00:26 AM7/12/18
to structuremap-users
Yes, it looks like Core.

Callen Barton

unread,
Jul 12, 2018, 11:48:09 AM7/12/18
to structuremap-users
This is how I use structuremap in aspnet core in my startup class. https://github.com/cal5fishbowl/ddd-guestbook/blob/master/src/CleanArchitecture.Web/Startup.cs


On Wednesday, July 11, 2018 at 5:29:14 PM UTC-6, Gibran Shah wrote:

Gibran Shah

unread,
Jul 13, 2018, 9:46:02 AM7/13/18
to structuremap-users
Thanks Callen,

I also found this which seems to work with ASP.NET Web:



Gibran
Reply all
Reply to author
Forward
0 new messages