Unity and Enterprise Library Data Access Blocks

I am learning DAL.

As I understand it, I can access my data through the database db = DatabaseFactory.CreateDatabase ();
as well as through a single container resolver.

What I don't understand, why do I need a unity container if I can do the same with DatabaseFactory?
 What are the benefits of using unity?

+3
source share
1 answer

The unity container goes beyond simply configuring and creating enterprise library objects. One way Unity can create objects for you automatically is by simply declaring the objects you need in your constructors.

public class Foo
{
    IExceptionManager _em;
    IDatabase _db;
    IServiceAgent _sa; // custom made service agent for accessing some other web service
    public Foo(IExceptionManager em, IDatabase db, IServiceAgent _sa)
    {
        _em = em;
        _db = db;
        _sa = sa;
    }
}

_em, _db _sa Unity. , . Unity - , , , .. ( )

, Unity, EntLib Unity. Unity , , , - .

+3

Source: https://habr.com/ru/post/1735712/


All Articles