0

Is it possible to have a ASP.NET OWIN self-host WebApi service running in one project, and include the WebApi controllers from another project, and how?

Right now, it seems like my hosting project doesn't include (/discovers) the controllers that I have in another project, which will result in an emptyApiDescriptions of Microsoft.Web.Http.Description.VersionedApiExplorer.

Jan_V
  • 4,244
  • 1
  • 40
  • 64
grmihel
  • 784
  • 3
  • 15
  • 40
  • Probably not quite what you are looking for, but you can create libraries that contain controllers and use them as modules if you are using .Net Core. [This video](https://www.youtube.com/watch?v=LoPlECp31Oo&index=1&list=FLmQYVKMxsF63fEjRoEQUeRg) is a little dated, the project demonstrated has been updated from .Net Standard 1.6 to 2.0. – Crowcoder Oct 10 '17 at 12:03
  • using .net 4.6, don't know if that change anything to your suggestion? – grmihel Oct 10 '17 at 12:17
  • The Orchard Modules project I referenced will not work on .net 4.6. – Crowcoder Oct 10 '17 at 12:19
  • This question has been asked again here: https://stackoverflow.com/questions/22493707/how-to-configure-web-api-2-to-look-for-controllers-in-a-separate-project-just It has both config and code way to implement this. – Athanasios Kataras Oct 10 '17 at 12:23
  • @AthanasiosKataras The only thing missing is, that solution is about ASP.NET MVC, my project is based on self-hosted service, so I'm missing some examples in the other threads unfortunately. – grmihel Oct 10 '17 at 12:58

1 Answers1

0

You can write your own controller factory as described here.

I have personally never tried it, as we keep controllers lean and reuse logic from our "service" layer, but why not try to derive from shared controllers.

public class MyController : SharedController {}

It might get more complicated, though, if SharedController has a constructor (for example IoC constructor injection).

sANDwORm
  • 191
  • 5