mercredi 11 janvier 2017

What pattern should apply to my REST Application?

I am having a problem in my web application Design. I am using Web API (ASP.NET Core 1.0) and I will implement a Generic Repository using Entity Framework.

My models are:

Planet, Coordinate, Territory, Building, Mine, Resource

A planet has a coordinate and 4 territories. Each territory has multiple buildings,mines and resources.

This entities will have their own repository (PlanetRepository, TerritoryRepository, MineRepository, BuildingRepository, ResourceRepository).

I want also to implement a service layer where each service has its own repository.

So, when I say "create me a planet with all his basic information", my application should create a planet, 4 territories associated to that planet, with 3 mines each and 2 buildings and 3 resources. This should be persisted on database, because I want to create all this info, because it is a game and by default I will create multiple planets that are automated and play by itself.

In this action I am working with 4 different entities and 4 repositories.

Because it is REST the url's should be like (this are examples):

GET/POST api/Planet - get all planets / create new planet

GET api/Planet/{planetId}/Territory - get all territories from planet id

GET api/Territory/{territoryId}/Mine - get all mines from territory id

GET api/Territory/{territoryId}/Building - get all buildings from territory id

GET api/Territory/{territoryId}/Resource - get all resources from territory id

So, has you can see, my TerritoryController has dependencies from 3 different services (MineService, BuildingService, ResourceService) and in the future could have more.

My Territory model will have a lot of information, it can have more child entities than now, so this means that my controller will have a lot of dependencies and I want to abstract all of this! I still cannot find the best solution...

So, what is(are) the best(s) option(s) or pattern(s) to solve my problem?

Aucun commentaire:

Enregistrer un commentaire