DI Lifetime / Intercepting Specific Methods? #154
-
Hi. Great library! I am considering using it to intercept calls to my repository classes to inject Transactions around them and have a couple questions. All samples I have seen for using AsyncInteceptor show the Inteceptors being injected as ‘Scoped’. My repository is currently injected as ‘Singleton’. I understand DI lifetime, but I’m not certain how I should inject these. I recently read that repository classes might be better injected as ‘Scoped’, particularly if Transactions are involved. Can you comment? Secondly, I believe Castle.Core allows interception of specific methods in an interface/class. This would be ideal for me, but I didn’t see a way to do it using AsyncInteceptor. Is this supported? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi Firstly, concerning scoped vs singleton of repository classes, that's down to your implementation. The terms repository and scope are overloaded concepts, and a detailed discussion is beyond the scope of this code repository (see what I mean?). Secondly, concerning intercepting specific methods, I'm unfamiliar with the feature of Castle.Core. But since this library sits on top of Castle.Core such a feature should be available to you unless I have inadvertently hidden it. One last point. The line between DI library API and Castle.Core is often confused. A DI library may code with to Castle.Core in mind, they don't tend to code considering this library (happy to be proven wrong, BTW). In my experience, there's usually a lower-level API of most DI libraries that allows you to use AsyncInterceptor, but you typically need to go digging for it. I hope this helps. |
Beta Was this translation helpful? Give feedback.
Hi
Firstly, concerning scoped vs singleton of repository classes, that's down to your implementation. The terms repository and scope are overloaded concepts, and a detailed discussion is beyond the scope of this code repository (see what I mean?).
Secondly, concerning intercepting specific methods, I'm unfamiliar with the feature of Castle.Core. But since this library sits on top of Castle.Core such a feature should be available to you unless I have inadvertently hidden it.
One last point. The line between DI library API and Castle.Core is often confused. A DI library may code with to Castle.Core in mind, they don't tend to code considering this library (happy to be proven wrong, BTW). In…