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)
-
0
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
-
0
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?
-
0
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(); } }
-
0
@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>