Closed davidkeaveny closed 6 years ago
@davidkeaveny I'm assuming you mean the IValidator<TCommand>
is not always registered and that's where you are running into the issue?
You can either explicitly mark the parameter as not required when it's registered using c.ExportDecorator<T>().WithCtorParam<TParam>().IsRequired(false)
or you can implicitly specify it by making the parameter optional (i.e. = null).
As for registering a default implementation you could register an open generic version of IValidator<T>
that always returns true. Closed implementations are used before open implementations (provided they are in the same scope).
How does the usage of .WithCtorParam()
work with an open generic registration? If my current registration code is:
c.ExportDecorator(typeof(ValidatingDecorator<>)).As(typeof(ICommandHandler<>));
I think this should do it.
c.ExportDecorator(typeof(ValidatingDecorator<>)).As(typeof(ICommandHandler<>)).WithCtorParam<object>().Named("validator").IsRequired(false);
Can I close this out?
Sorry, yes this can be closed.
I have the following interface:
which I then want to decorate with a validating decorator:
At the moment, Grace throws a
LocateException
if it cannot resolve the dependency - how can I make it either a) return null (which I then handle internally) or b) return a default implementation?