Do i need to always inherit IService?

Jun 22, 2015 at 4:55 AM
Hello and Good Day!

I would like to ask regarding IService, i have a basic business logic that there is no need to add a custom methods and i found out that i need to create an interface inheriting IService.

Do i need to always inherit IService?
Jul 2, 2015 at 1:41 PM
Hi Kagaw,

No you do not have to always define a class that implements IService. This si one of the reasons we decided to go with the framework. You can get an entire CRUD/Query service class for free simply by defining the object in the IoC container.

If you are exposing CRUD/QUERY only (no custom functions requierd) it IS acceptable to inject a Service<T> into your controller where T is the type of entity the service will expose. Your controller can expect IService<T>.

In the event you need to add custom functions to your service class you would have to define an interface for the service class, define your new method, build a class that inherits Service<T> and implements your newly defined interface.
Jul 2, 2015 at 3:46 PM
Edited Jul 2, 2015 at 3:50 PM
Hi MattHoffman,

So in my controller for example:

public class CustomerController : controller
readonly IService<Customer> _service;
public customerController(IService<Customer> service, IUnitOfWork<...)
{
_service = service;
}

Then in my IOC startup:

Bind<IService<Customer>,Service<Customer>();

I get it now BUT
What IF, i have a custom logic inside the method in service CRUD? but not adding a new method to it.
Jul 6, 2015 at 4:50 AM
Dear kagaw3000,

When i injected Iservice like you the system said: "An error occurred when trying to create a controller of type 'DictionariesController'. Make sure that the controller has a parameterless public constructor."

but when i remove it everything working fine, what's the problem here?

My controller:

private readonly IDictionaryService _service;
    private readonly IService<DictionaryItem> _itemService;
    private readonly IUnitOfWorkAsync _unitOfWork;

    public DictionariesController(
        IDictionaryService service, 
        IUnitOfWorkAsync unitOfWork, 
        IService<DictionaryItem> itemService)
    {
        _service = service;
        _unitOfWork = unitOfWork;
        _itemService = itemService;
    }
my IOC

container
            // register data context.
            .RegisterType<IDataContextAsync, AtlasContext>(new PerRequestLifetimeManager())

            // register unit of work.
            .RegisterType<IUnitOfWorkAsync, UnitOfWork>(new PerRequestLifetimeManager())

            // register repositories.
            .RegisterType<IRepositoryAsync<Client>, Repository<Client>>()
            .RegisterType<IRepositoryAsync<User>, Repository<User>>()
            .RegisterType<IRepositoryAsync<RefreshToken>, Repository<RefreshToken>>()
            .RegisterType<IRepositoryAsync<Dictionary>, Repository<Dictionary>>()
            .RegisterType<IRepositoryAsync<DictionaryItem>, Repository<DictionaryItem>>()

            // register services.
            .RegisterType<IIdentityService, IdentityService>()
            .RegisterType<IClientService, ClientService>()
            .RegisterType<IRefreshTokenService, RefreshTokenService>()
            .RegisterType<IDictionaryService, DictionaryService>()
            .RegisterType<IService<DictionaryItem>, Service<DictionaryItem>>()
            ;