public DeliverySchedulingObjectContext()
{
}
public DeliverySchedulingObjectContext(DbContextOptions<DeliverySchedulingObjectContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new OrderShippingMethodCapacityMappingMap());
modelBuilder.ApplyConfiguration(new ShippingMethodCapacityMap());
base.OnModelCreating(modelBuilder);
}
public virtual int ExecuteSqlCommand(RawSqlString sql, bool doNotEnsureTransaction = false, int? timeout = null, params object[] parameters)
{
using (var transaction = this.Database.BeginTransaction())
{
var result = this.Database.ExecuteSqlCommand(sql, parameters);
transaction.Commit();
return result;
}
}
public string CreateDatabaseScript()
{
this.DropPluginTable(this.GetTableName<OrderShippingMethodCapacityMapping>());
this.DropPluginTable(this.GetTableName<ShippingMethodCapacity>());
return this.Database.GenerateCreateScript();
}
public void Install()
{
#region Create Tables
var dbScript = CreateDatabaseScript();
Database.ExecuteSqlCommand(dbScript);
this.DropStoredProcedure(Constants.LoadAvailableDeliveryDateTimesStoredProcedureName);
this.CreateStoredProcedure(Constants.LoadAvailableDeliveryDateTimesStoredProcedureName, Constants.LoadAvailableDeliveryDateTimesEncryptedStoredProcedureFileName);
}
public virtual new DbSet<TEntity> Set<TEntity>() where TEntity : BaseEntity
{
return base.Set<TEntity>();
}
public IEnumerable<TElement> SqlQuery<TElement>(string sql, params object[] parameters)
{
throw new NotImplementedException();
}
public void Uninstall()
{
this.DropPluginTable(this.GetTableName<OrderShippingMethodCapacityMapping>());
this.DropPluginTable(this.GetTableName<ShippingMethodCapacity>());
this.DropStoredProcedure(Constants.LoadAvailableDeliveryDateTimesStoredProcedureName);
}
public virtual string GenerateCreateScript()
{
return this.Database.GenerateCreateScript();
}
public IQueryable<TQuery> QueryFromSql<TQuery>(string sql) where TQuery : class
{
throw new NotImplementedException();
}
public IQueryable<TEntity> EntityFromSql<TEntity>(string sql, params object[] parameters) where TEntity : BaseEntity
{
throw new NotImplementedException();
}
public void Detach<TEntity>(TEntity entity) where TEntity : BaseEntity
{
throw new NotImplementedException();
}
and dependency registrar :
builder.RegisterType<ShippingMethodCapacityService>().As<IShippingMethodCapacityService>().InstancePerLifetimeScope();
builder.RegisterType<OrderShippingMethodCapacityMappingService>().As<IOrderShippingMethodCapacityMappingService>().InstancePerLifetimeScope();
builder.RegisterPluginDataContext<DeliverySchedulingObjectContext>("nop_object_context_orderfulfillment_deliveryscheduling");
builder.RegisterType<EfRepository<OrderShippingMethodCapacityMapping>>()
.As<IRepository<OrderShippingMethodCapacityMapping>>()
.WithParameter(ResolvedParameter.ForNamed<IDbContext>("nop_object_context_orderfulfillment_deliveryscheduling"))
.InstancePerLifetimeScope();
builder.RegisterType<EfRepository<ShippingMethodCapacity>>()
.As<IRepository<ShippingMethodCapacity>>()
.WithParameter(ResolvedParameter.ForNamed<IDbContext>("nop_object_context_orderfulfillment_deliveryscheduling"))
.InstancePerLifetimeScope();
but when open list of plugin from admin panel get this error:
ComponentNotRegisteredException: The requested service 'Microsoft.EntityFrameworkCore.DbContextOptions`1[[Resanehlab.Plugin.OrderFulfillment.DeliveryScheduling.Data.DeliverySchedulingObjectContext, Nop.Plugin.OrderFulfilment.DeliveryScheduling, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable<Parameter> parameters)