I'm attempting to follow an Onion Architecture for a WebAPI services hosted on OWIN/Katana.
I have a solution structure like this:
I'd like the DependencyResolution project to inject the dependencies for the WebApi project. The DependencyResolution does have a build task to output to the WebApi project's output folder.
I'm following the approach outlined here, using Autofac and the DotNetDoodle.Owin.Dependencies NuGet package:
http://www.tugberkugurlu.com/archive/owin-dependencies--an-ioc-container-adapter-into-owin-pipeline
However, in registering the services in my Startup class, the call to RegisterApiControllers() will fail. The DepenedencyResolution assembly will be the first to execute so it won't be able to get the assembly containing the ApiContollers (WebAPI assembly):
public IContainer RegisterServices()
{
ContainerBuilder builder = new ContainerBuilder();
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterType<MyRepo>()
.As<IRepo>()
.InstancePerLifetimeScope();
return builder.Build();
}
Is resorting to Assembly.Load() the only viable option here, or should I just forgo the idea of keeping the DependencyResolution project isolated and just refer to it from the WebApi project (seems a little less-than-oniony)?
You can use the name of the Web API assembly to get its instance:
builder.RegisterApiControllers(Assembly.Load("WebApiAssembly"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With