0

What is the difference between unity container and unit of work(if there is any), as I understand both are doing same thing, but how to determine which one to use.

I need to be sure, that I understand it well and there is no any difference.

Matías Fidemraizer
  • 59,064
  • 16
  • 107
  • 181
Tornike Choladze
  • 202
  • 1
  • 3
  • 8

2 Answers2

1

Unity is an inversion of control container, where inversion of control is a design pattern, and unit of work is another design pattern...

The main difference between the two is they're absolutely different design patterns, there's no criteria to match both patterns and find out similarities.

OP said...

I didn't know about inversion of control, read that link and have done some search, but still both are related with dependency injection and no one uses combination of them(both of it), they are using just one of them

Dependency injection is an approach to inversion of control.

In the other hand, unit of work has nothing to do with inversion of control or dependency injection. Again, unit of work and inversion of control/dependency injection are different design patterns.

Perhaps you can inject dependencies in an unit of work, or inject an unit of work somewhere to decouple your architecture from the concrete implementation of the so-called unit of work. There's a big difference from comparing two design patterns from just understanding that design patterns can cooperate to build a software stack.

Matías Fidemraizer
  • 59,064
  • 16
  • 107
  • 181
  • I don't knew about inversion of control, read that link and have done some search, but still both are related with dependency injection and no one uses combination of them(both of it), they are using just one of them – Tornike Choladze Dec 26 '15 at 20:36
  • thx, will be nice if u suggest some examples of that patterns – Tornike Choladze Dec 27 '15 at 08:08
  • @ITTeam Well.. I believe you're end up learning them using google earlier than if I give you a sample. Actually, if you want to be a design pattern master and learn more about inversion of control and unit of work, maybe you can buy this book: http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420/ref=sr_1_1?s=books&ie=UTF8&qid=1451214684&sr=1-1&keywords=patterns+of+enterprise+application+architecture – Matías Fidemraizer Dec 27 '15 at 11:12
0

Your Ioc container, unity, may or may not contain a hard implementation at the other end that is using unit of work. You will implement your interfaces using some specific class that satisfies your generic interface definitions but using a specific backing store such as Entity Framework, LinqToSql, Ado Sql Commands, test stubs, etc.. Unit of work would not be applicable if you are using Ado sql commands so it is usually a good idea to only include generic functionality in your ioc "service contracts".

Ross Bush
  • 13,367
  • 2
  • 30
  • 50