-2

I have made a project in Umbraco using backoffice completely.But Now I am trying to apply concept of dependency injection(which I may have used in past..but not by that specific name) in that project. and after loads of searching.I now know the concept of dependency injection(I think),in which we are supposed to use classes and constructor to restrict the input supplied to a function in terms of type,value.

But how am I suppose to make that umbraco project from that.I once tried making a strongly typed.It looks much like that which I am supposed to do now.
I also took reference from these articles.

Is it possible to use dependency injection with Umbraco 7 ContentService event handlers?

Why does one use dependency injection?

But still I am kind of stuck..Is there any other way to do unit testing in umbraco.

Bhawna Jain
  • 709
  • 10
  • 27
  • 3
    What do you want to achieve with DI? Do you want to have your custom controllers and classes to use DI? I have used the following page to succesfully implement DI with autofac https://our.umbraco.org/documentation/reference/using-ioc – Mark Sep 17 '17 at 09:40
  • down votter..kindly explain your action.. – Bhawna Jain Oct 04 '17 at 06:03

1 Answers1

2

Yes, you can! :)

Basically, the starting URL for using IoC and DI with Umbraco was already shared. It's here: https://our.umbraco.org/documentation/reference/using-ioc. You can of course use any of the avaialable containers, the example is just for autofac. You just need to remember to initialize container when Umbraco starts (using event handlers).

For Unit Testing resources I would point you first to tests made by Umbraco itself: https://github.com/umbraco/Umbraco-CMS/tree/dev-v7/src/Umbraco.Tests. You can explore how the core team is testing their code and even reference this library and make use of it in your solution.

There are some other useful materials to start unit testing with Umbraco. To list a few:

I think it will be enough to start doing it.

Marcin Zajkowski
  • 1,668
  • 10
  • 14