Closed glcheetham closed 6 years ago
Also, I've found that using System.Web.Mvc.DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
makes my dependencies resolve but breaks the Umbraco backoffice (7.4.3)
Here's a stack trace from the backoffice:
Exception Details
System.NullReferenceException: Object reference not set to an instance of an object.
[defaultdialogs_stacktrace]
at Umbraco.Web.WebApi.Filters.DisableBrowserCacheAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
at System.Web.Http.Filters.ActionFilterAttribute.OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
Hi, @clausjensen has been working on getting these updated, sorry for the out-dated docs, we'll try to get this updated as soon as possible. Quite a lot of developers are using Autofac so would be worth searching or asking on the forum for advice: http://our.umbraco.org
Thanks for the update. I'd love to help out, I feel quite strongly about dependency injection and IOC. I'll send a PR over and reference this issue when I get time to share what I've learned experimenting with DI in Umbraco.
@glcheetham check your twitter ;)
@clausjensen Thanks a bunch. So I can refer back to this issue in the future, your gist was just what I needed. I was struggling to figure out which of Umbraco's types I needed to register with Autofac to get the backoffice working again.
Hi guys, To me it looks like the Docs, https://our.umbraco.org/documentation/reference/using-ioc, has been updated.
Is it safe to assume this can be closed down? 😁 -Sofie
Yep I think we can close it for now .. can reopen if we think there's a need for further docs
Brilliant! Thanks @clausjensen
Think this needs opening again. https://docs.umbraco.com/umbraco-cms/reference/using-ioc might be ok for experts but it's not helping at wrt the registering of classes. Thought it was supposed to have been made easier?! The docs are very confusing and unclear.
https://our.umbraco.org/documentation/reference/using-ioc
I found the documentation page on implementing IOC unclear, they don't specify that the given examples will not compile without a reference to the Autofac MVC package alongside the mentioned container Autofac. (For
ContainerBuilder.RegisterControllers
andAutofacDependencyResolver
)