2

The StructureMap.WebApi2 package has a dependency to StructureMap.MVC5 which in return has a dependency to System.Web.Mvc.

As we are building a Web API-only project we don't want to include the System.Web.Mvc assembly.

Is it possible to use StructureMap in Web API 2 without this dependency?

adamfinstorp
  • 1,627
  • 3
  • 17
  • 26

2 Answers2

1

Sadly no.

StructureMap is made for MVC so it obviously depends on it.

Why do you insist on using StructureMap though? All it does is DI and there are many other options to do DI in Web API, like Ninject and Unity.

Mihai Dinculescu
  • 19,743
  • 8
  • 55
  • 70
  • I have previously successfully used Ninject and Autofac. Since other teams here are using StructureMap this was the natural choice. Maybe it is time to reconsider :) – adamfinstorp Dec 03 '14 at 11:45
  • Maybe in time StructureMap will offer a Web API version, until then you are sadly stuck with some other solution. – Mihai Dinculescu Dec 03 '14 at 11:50
  • Could the answer here be a workaround for now? Or will it require the same dependencies?http://stackoverflow.com/questions/18896758/webapi-apicontroller-with-structuremap – adamfinstorp Dec 03 '14 at 12:02
  • The dependencies will be the same. You could try to remove the reference yourself but who knows. I still consider that you'll be better off with a solution made for Web API. – Mihai Dinculescu Dec 03 '14 at 12:07
  • Ok. Yes, I will go with Autofac instead. – adamfinstorp Dec 04 '14 at 08:42
0

Autofac is a good Ioc for Web Api, and Autofac is far better in documentation than structuremap, most of the structuremap examples are old and useless for version 3 for example.

  • Here, you can find a quick start for using Autofac.
  • Here, you can find a good start-up for using Autofac with OWIN.

Hope that helps.

Omar.Alani
  • 4,050
  • 2
  • 20
  • 31