Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs on implementing IOC unclear #342

Closed
glcheetham opened this issue May 23, 2016 · 9 comments
Closed

Docs on implementing IOC unclear #342

glcheetham opened this issue May 23, 2016 · 9 comments

Comments

@glcheetham
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

@glcheetham check your twitter ;)

@glcheetham
Copy link
Contributor Author

@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
Copy link
Contributor

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
Copy link
Contributor

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

@sofietoft
Copy link
Contributor

Brilliant! Thanks @clausjensen

@craigs100
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants