Open
Description
Hi,
I am trying to implement a Custom Value generator. Whchi is getting number from other DB.
My code is as follows.
public class MyValueGenerator: ValueGenerator<int>
{
private ISeqDefinitionRepository _repository;
public MyValueGenerator(ISeqDefinitionRepository repository)
{
_repository = repository;
}
public override bool GeneratesTemporaryValues => false;
public override int Next(EntityEntry entry)
{
if (entry == null)
{
throw new ArgumentNullException(nameof(entry));
}
int res = _repository.NextValue(1);
return res;
}
}
On Model Creating
private void ConfigureMfr(EntityTypeBuilder<Mfr> builder)
{
builder.Property(b => b.MfrId).HasValueGenerator<MyValueGenerator>();
}
I am getting following Error
Cannot create instance of value generator type 'MyValueGenerator'. Ensure that the type is instantiable and has a parameterless constructor, or use the overload of HasValueGenerator that accepts a delegate.
No parameterless constructor defined for this object.
Requesting to guide met to get the instance of the service in custom ValueGenerator Class.
Further technical details
EF Core version: 2.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Visual Studio 2017
Thanks & Regards,
Easwar