Base solution for your next web application
Open Closed

Repository and AppService that will not access database #823


User avatar
0
hussein created

Hi,

I want to add an AppService and a Repository for Azure and this repository will not access database it just doing somethings on cloud. so, if i added something like this

public interface IBlobAppService : IApplicationService public interface IBlobRepository : IRepository

Will these open a connection to the database? if yes, so how to make the DI working without opening a connection to the database because this service and repository will not access the database.

Thanks,


4 Answer(s)
  • User Avatar
    0
    nmtoan07 created

    Hi, When program started, DI framework will collect all instance which IApplicationService implemented. The class inherited from IApplicationService will be used for your purpose. Ex: You have following: IExampleService: IApplicationService ExampleService: IExampleService If you don't call database, it doesn't have any problem. Service layer is separated with database.

    Best regards

  • User Avatar
    0
    hussein created

    Hi,

    Thank you for replying.

    What about IRepository, if i did an interface called IExambleRepository implements IRepositoy will this open a connection to the database?

  • User Avatar
    0
    nmtoan07 created

    OK, fine! I will explain for this: First, repository is just for handler for each Table (in my opinions). But you must open connection first. Related to this:http://www.aspnetboilerplate.com/Pages/Documents/Unit-Of-Work If you want to open connection auto, mark method with [UnitOfWork] attribute. If you want to open connection by hand, inject IUnitOfWorkManager and implement by follow: Ex:

    public void CreatePerson(CreatePersonInput input)
        {
            var person = new Person { Name = input.Name, EmailAddress = input.EmailAddress };
           
           //_unitOfWorkManager.Begin() will open connection
           using (var unitOfWork = _unitOfWorkManager.Begin())
            {
                _personRepository.Insert(person);
                _statisticsRepository.IncrementPeopleCount();
    
                unitOfWork.Complete();
            }
        }
    
  • User Avatar
    0
    hikalkan created
    Support Team

    @Hussein, you don't have to implement IRepository or IApplicationService. You can implement ITransientDependency to make DI work, if you just want that. See docs: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Dependency-Injection#DocRegisterDependencies">http://www.aspnetboilerplate.com/Pages/ ... pendencies</a>