previously I registered the repository as follows:
container.Register(
typeof(IAsyncRepository<>),
typeof(AsyncRepository<>),
reuse: Reuse.Scoped,
made: Parameters.Of.Details((request, p) =>
p.ParameterType
.GetGenericDefinitionOrNull() == typeof(IDeletingStrategy<>)
&& (!p.ParameterType
.GetGenericParamsAndArgs()
.FirstOrDefault()
?.IsAssignableTo<IUndeletable>() ?? false) // ToDo check logic here
? ServiceDetails.Of(value: null)
: null)); // the default injection behavior
Here I define which deletion strategy to assign to the model's repository. Now the task has become more complicated, I have added a second repository AsyncCompileRepository: IAsyncRepository". The base repository needs to be registered with the key RepositoryType.Base, and compile with the key RepositoryType.Compile. Will the following registration work correctly:
container.Register(
typeof(IAsyncRepository<>),
typeof(AsyncRepository<>),
reuse: Reuse.Scoped,
serviceKey: RepositoryType.Base,
made: Parameters.Of.Details((request, p) =>
p.ParameterType
.GetGenericDefinitionOrNull() == typeof(IDeletingStrategy<>)
&& (!p.ParameterType
.GetGenericParamsAndArgs()
.FirstOrDefault()
?.IsAssignableTo<IUndeletable>() ?? false) // ToDo check logic here
? ServiceDetails.Of(value: null)
: null)); // the default injection behavior
container.Register(
typeof(IAsyncRepository<>),
typeof(AsyncCompileRepository<>),
reuse: Reuse.Scoped,
serviceKey: RepositoryType.Compile,
made: Parameters.Of.Details((request, p) =>
p.ParameterType
.GetGenericDefinitionOrNull() == typeof(IDeletingStrategy<>)
&& (!p.ParameterType
.GetGenericParamsAndArgs()
.FirstOrDefault()
?.IsAssignableTo<IUndeletable>() ?? false) // ToDo check logic here
? ServiceDetails.Of(value: null)
: null)); // the default injection behavior
And how to register the second repository so that the first one is always used by default, and the second one is only used if we explicitly specify the serviceKey attribute, while also correctly taking the deletion strategy?