Do I need to Separate Business Objects and Business Logic? Asp.net MVC with Repository Pattern in C# -


i'm having trouble finding answer this. basically, right have these layers:

  • data access layer (where repositories are). has namespace hello.data
  • business layer (where business objects are). has namespace hello.business

my repositories return business objects. example, getcustomer return customer.

however, in business layer, want add logic use repository add/update/delete records, can reuse methods in mvc controllers. doesn't work though, since can't have data access layer reference business layer , have business layer reference data access layer. (it creates circular reference not allowed).

what guys think best solution? should put business logic it's own project?

so instead of:

hello.data hello.business 

i'll have:

hello.data hello.business hello.businesslogic 

or thinking wrong? thanks!

why separate business logic business models? logic should in models.

the business logic layer shouldn't have reference anything, aside maybe small common utility libraries. basically, should have no dependencies on infrastructure concerns (like application technologies, database technologies, etc.). should contain just business logic.

all other layers should reference business logic layer.

this doesn't work though, since can't have data access layer reference business layer , have business layer reference data access layer.

correct! mistake in design business logic layer references data access layer at all. shouldn't.

it should, however, contain interfaces data access (and other infrastructure concerns) implemented data access layer. business logic layer needs know interfaces, doesn't know or care implements interfaces.

a dependency injection container used connect implementations interfaces.

  • the application layer references dependency injection layer initialize , pass container (which implements generic business logic interface) business logic layer.
  • the dependency injection layer references business logic layer know interfaces , references data access (and other infrastructure) layer know implementations.
  • the data access (and other infrastructure) layer references business logic layer know interfaces implement.
  • the business logic layer doesn't reference anything. requires configured dependency injection container , uses container implementations interfaces.

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -