Question

Im currently working on a project which is based on Onion Architecture . The above image Shows the Solution.

In the Infrastructure We have External Service . But the WebAPI has access only to Core .

But in the Web API project i want to access the some of the models exposed by the external services ? How can we achieve this without adding reference to Infrastructure in the Web API .

Or we implemented Onion Architecture wrong?

Was it helpful?

Solution

conceptually you are on the right track, but the implementation isn't a hard a fast rule. to start you don't need 5+ projects at most you need 3 (web ui css/js/views, logic/controllers, code, and tests). and really you probably only need 2 (the application, the tests)

the idea of layers is conceptual, not physical. And there is not a hard and fast rule that says the layers must be completely segregated. rather the core focus of the application is what the application does. as you get into the details of how that is implemented you move to the outer layers.

in this instance you need to access data retrieved from an external service. create an abstraction for the external service IExternalServiceAdaptor. The interface may reside in the domain or server layer, but the implementation might reside in an infrastructure or outer layer where the details of how to call the external service are encapsulated within an implementation of IExternalServiceAdaptor.

If you stick with your physical separation you would have an interface in Core and the implementation in Infrstructure.

OTHER TIPS

But in the Web API project i want to access the some of the models exposed by the external services ?

Actually, your WebApi project should only manipulate object defined in your Core project. As Jason said, calls to any external services should be encapsulated within an implementation of an interface that resides in Core. And this is where models exposed by your external services will be mapped to your Core models.

Have a look at Matt Hidinger's source code on CodePlex here: http://onionarch.codeplex.com/ and check how he deals with this kind of problem, it's pretty straightforward and easy to understand.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top