umbraco / UmbracoDocs

The official Umbraco Documentation
https://docs.umbraco.com
MIT License
266 stars 770 forks source link

Docs on implementing IOC unclear #342

Closed glcheetham closed 6 years ago

glcheetham commented 8 years ago

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 and AutofacDependencyResolver)

glcheetham commented 8 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()
Shazwazza commented 8 years ago

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

glcheetham commented 8 years ago

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.

clausjensen commented 8 years ago

@glcheetham check your twitter ;)

glcheetham commented 8 years ago

@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.

sofietoft commented 6 years ago

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

clausjensen commented 6 years ago

Yep I think we can close it for now .. can reopen if we think there's a need for further docs

sofietoft commented 6 years ago

Brilliant! Thanks @clausjensen

craigs100 commented 1 year ago

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.