MVC Razor: How can I initialize DependencyResolver.Current.GetServiceEntity?

0

I comment quickly: for the architecture of the system there is an "easy" way to get to the database to make update and delete, which is through DependencyResolver . Copy code so you have an idea:

IEntityService<Persona> servicePersona = DependencyResolver.Current.GetService<IEntityService<Persona>>();

With this form I can go to the base and make inquiries in the following way:

Persona resultPersona = new Persona();            
resultPersona = servicePersona.Queryable().ToList().Where(c=>c.CuilCuit==Id).FirstOrDefault();

This works perfect, the problem is when I want to make update / delete, since I do not make an assignment, but I make a direct call to a non-initialized class:

IAssistant<Persona> servicePersona2 = DependencyResolver.Current.GetService<IAssistant<Persona>>();

It should be easy to delete with the following code:

servicePersona2.Service.Delete(servicePersona.Queryable().ToList().Where(c => c.CuilCuit == "1111111111").FirstOrDefault());
servicePersona2.UnitOfWork.SaveChanges();

The problem is that I get the following error:

Did anyone have the opportunity to do an update / delete in a similar way? How did they resolve the initialization? Thanks!

    
asked by seojedaperez 15.05.2017 в 17:32
source

1 answer

0

In the end I chose to install the Nuget "Entity Framework" package and build the base and the models from 0, with that all my problems were solved when using connectors against the base, in fact, entity framework offers you a Rapid communication without the need of so much code. I leave the link for doubts if someone wants to use it:

link

    
answered by 18.05.2017 в 15:11