Enter C# Unity Container, Inversion of Control

Coding in C# is pretty straight forward although sometimes you see errors every now and then. Working with WPF(Window Presentation Foundation) and MVVM can get really complex with large projects you can get lost in the sea of codes.

One thing Im going to talk about is Dependency, we use it all the time. Sometimes we need an model object that represent the data in our class and consume it, sometimes we need a database layer class to every object that will communicate with our server.

Inversion of Control is a pattern on how to pass dependency object through constructor. Enter Unity Container, its a Microsoft object that handles dependencies through the use of IoC.

We create the instance of the UnityContainer object and register types so unity will construct our dependency for us. You then resolve the classes that are involved in the dependency by calling obj.Resolve<typeof>(). This will chain up the classes with their dependency object injected.

Check links below for a simple explanation of the architecture.

https://www.youtube.com/watch?v=CWwe9Z0Gyew PART 1
https://www.youtube.com/watch?v=PsIbevgzQQE PART 2

Credit to the author

Leave a Reply

Your email address will not be published. Required fields are marked *