Question

I am developing a ASP.NET MVC application following the Onion Architecture.
I would like to know the ModelServices in the Core can refer another ModelService?

The ModelServices are concrete implementations and not inheriting any interfaces. I write the business logic in the Model Services and it depends on the Repositories.

Am I doing it correct?

Was it helpful?

Solution

The ModelServices are concrete implementations and not inheriting any interfaces.

If I refer to your comment that says:

ModelServices are the Business/Domain Services

... then those services should obviously inherit from interfaces!

Every layer in your application (including UI) that needs to access a service, will manipulate services interfaces without knowing the service implementation. Remember that the outermost layer of your onion architecture is the Dependency Resolution Layer this is where service interfaces will be bound at run time with the right service implementation.

Now to answer your question:

I would like to know the ModelServices in the Core can refer another ModelService?

Service implementation classes will only refer other services interfaces. In the following example, FooService needs service1 & service2 to to his job:

namespace MyBusiness.Core.Services
{
  internal class FooService: IFooService
  {
    public FooService(IService1 service1, IService2 service2)
    {
      _service1 = service1;
      _service2 = service2;
    }

    ...
  }
}

Everything will be bound at run time as well!

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