using EVCB_OCPP.Domain; using EVCB_OCPP.Packet.Messages.SubTypes; using EVCB_OCPP.WSServer.Dto; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using System; using System.Linq; using System.Threading.Tasks; namespace EVCB_OCPP.WSServer.Service { public interface IBusinessService { Task Authorize(string chargeBoxId, string idTag); Task NotifyFaultStatus(ErrorDetails details); Task NotifyConnectorUnplugged(string chargeBoxId,string data); } public class BusinessServiceFactory { public BusinessServiceFactory(IServiceProvider serviceProvider, IDbContextFactory mainDBContextFactory) { this.serviceProvider = serviceProvider; this.mainDBContextFactory = mainDBContextFactory; } private readonly IServiceProvider serviceProvider; private readonly IDbContextFactory mainDBContextFactory; public async Task CreateBusinessService(string customerId) { bool isCallOut = false; using (var db = this.mainDBContextFactory.CreateDbContext()) { isCallOut = await db.Customer.Where(x => x.Id == new Guid(customerId)).Select(x => x.CallPartnerApiOnSchedule).SingleOrDefaultAsync(); } //return isCallOut ? new OuterBusinessService(customerId) : new LocalBusinessService(customerId); if(isCallOut) { OuterBusinessService outerBusinessService = serviceProvider.GetService(); outerBusinessService.CustomerId = customerId; return outerBusinessService; } LocalBusinessService toReturn = serviceProvider.GetService(); toReturn.CustomerId = customerId; return toReturn; //return isCallOut ? new OuterBusinessService(customerId) : } } }