Dataportal injection enhancement #4629
Unanswered
ajohnstone-ks
asked this question in
Ideas
Replies: 1 comment 2 replies
-
This makes sense to me and is something I think would be good for v10. The default should probably be to require the service, which is a breaking change as you say. Though we could set the default to be as-is and avoid the breaking change. I'll create an issue from this discussion. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In Csla the data portal supports DI via the
[Inject]
attribute on method parameters which should be injected rather than be treated as data inputs to the method.This works well, but one aspect I find particually frutrating is that it seems that Csla is using
ServiceProvider.GetService
to resolve these dependencies. To date I've never added something to be injected an treated it as optional, but its easy to forget to register things in the injection container (or sometimes it depends on something else which was not registered correctly), which leaves the data portal method throwing a NullReferenceException when you try to use your dependency.I propose making adding a property to the
Inject
attributeIsOptional
which defaults tofalse
. If false, use GetService, and if true, use GetRequiredService. I understand this would be a breaking change, so perhaps there's could also be a way to configure what the default value of the attribute should be if not set.I think this would make finding dependency issues easier, while still allowing the possiblity that some dependencies are optional.
Any thoughts on this change?
Beta Was this translation helpful? Give feedback.
All reactions