Search code examples
asp.net-mvcrepository-patternservice-layer

Question about Interfaces and DI?


I am using the Service/Repository/EF/POCO pattern in a MVC app, and had a couple questions about the Interfaces.

1) Should I make an Interface per Service? 2) Should I make an Interface per Repository?

Or, should I have a generic interface per layer (IService(Of T), IRepository(Of T)).

What I dont understand is how in the controller say, it takes a IService(Of Category) interface in it's constructor, how do I implements the methods in the concrete class?

Public Class HomeController
    Inherits System.Web.Mvc.Controller

    Private _Service As IService(Of Category)

    Public Sub New(ByVal Service As IService(Of Category))
        _Service = Service

    End Sub

    Function Index() As ActionResult

        Return View()
    End Function

End Class

The _Service does not have the methods of my concrete CategoryService class?

Make any sense?


Solution

  • Use concrete interface for service. If your services can be described by generic interface you most probably don't need them at all. Generic interface is often used for repositories because repositories usually offer same core methods.