Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hoping somebody can point me in the right direction. I am trying to add dependency injection with Autofac to my new Umbraco8 (8.1.5) App.
It seems the registration of types is simply not being picked up. Here is the error from my controller (inheriting surfacecontroller) ...
Unresolved dependency [Target Type: ttweb.Controllers.MemberController], [Parameter: myAwesome(ttweb.common.Helpers.IMyAwesomeContext)], [Requested dependency: ServiceType:ttweb.common.Helpers.IMyAwesomeContext, ServiceName:]
You can see I am just using a simple test class - MyAwesomeContext which implements IMyAwesomContext.
I am using the composer / component setup to fire during startup (because ApplicationEventHandler has been removed from Umbraco8).
So Autofac registration (of test class and a keyed index) takes place as follows ...
*[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class MyComposer : IUserComposer
public void Compose(Composition composition)
var domainAssemblies = AppDomain.CurrentDomain.GetAssemblies();
var assembly = GetType().Assembly;
var builder = new ContainerBuilder();
// register all controllers found in your assembly
.Where(type => type.GetInterfaces().Contains(typeof(ITransform)))
.Keyed<ITransform>(transform => transform.Name);
var container = builder.Build();
This all worked absolutely fine in another Umbraco7 (7.6.5) app I am running. Is the lighinject or umbraco DI somehow interfering with Autofac ? .....
Any help would be much appreciated.
Umbraco 8 has internal IoC using LightInject, maybe you can use LightInject instead of Autofac?
Thanks for the reply. I guessed by the lack of any kind of response to this question that Umbraco removed the flexibility of using our own dependency injection model. In my case Autofac. There could be a way of doing it, but clearly not as straight forward as with Umbraco 7. I had a DI pattern for my Umbraco 7 sites, which I wanted to use with Umbraco 8. So have had to change afew things to fit in with their lightInject :/.
I think the right sentace is insert flexability to core :)
In my expirince LightInject is much faster than Autofac
you ca see here how to use it, it should be very simple to use
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted