Base solution for your next web application
Open Closed

Access to entity from static class #1830


User avatar
0
andmattia created

Is possible to access to a entity (via manager) in a static class?

I have a method and I make a static extension if I want to give data from data base is possibile to do that? How?

mattia


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Possible, but not suggested (because statics are bad, breaks testability). Short answer:

    var yourEntity = IocManager.Instance.Resolve<IRepository<YourEntity>>().Get(42); //42 is the id of your entity.
    

    A better code should use ResolveAsDisposable in a using statement, but I did write like that for simplicity.

  • User Avatar
    0
    andmattia created

    Thank for your replay @hikalkan.

    Ok I need to change my approch and use IOC from manager without do it on static class.

    mat