-
I a have a Data Access Layer implementing the repository pattern and accepting CancellationTokens. I would like to take advantage of this in my application, and pass a CancellationToken from the presentation layer (a REST web api) all the way down to the concrete DAL. I'm using .net 9 and CSLA 9. Here's some example code, from the DataPortal Insert operation of a root business object with children:
This code compiles and seems to work. However, the CSLA analyzer complains: CSLA0010 Operation argument types must be serializable. So I am wondering whether this is the correct way to do it, or whether there is a subtle bug introduced? Another, slightly related, question: is there any difference between using the [Inject] CSLA attribute, and the following code?
would you recommend the one over the other? I'm simply considering the second option to make method signatures more concise, now that I'll be adding the cancellation tokens to them. Thank you for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
CancellationTokens are designed to be used within a single process. CSLA is designed for the DataPortal to run in a single process or cross process (also called remote). That's why you are getting CSLA0010, non serializable items like CancellationToken can not be used in cross process situations. However, if you are always going to use an in process data portal and are OK with closing the door to easily making it cross process in the future, I suspect it would still work if you suppressed the error. I've never tried it though. But that is the reason you are seeing that waring. As far as I know it also isn't a supported scenario (?) so all disclaimers about even if it works today, it may not work in future versions would apply. As far as your question I would use the [inject] attribute. Otherwise you are directly using the service locator pattern instead of dependency injection. Granted DI has a centralized service locator, but it is normally considered easier to unit test and scaffold if you use Dependency Injection. |
Beta Was this translation helpful? Give feedback.
CancellationTokens are designed to be used within a single process. CSLA is designed for the DataPortal to run in a single process or cross process (also called remote). That's why you are getting CSLA0010, non serializable items like CancellationToken can not be used in cross process situations.
However, if you are always going to use an in process data portal and are OK with closing the door to easily making it cross process in the future, I suspect it would still work if you suppressed the error. I've never tried it though. But that is the reason you are seeing that waring. As far as I know it also isn't a supported scenario (?) so all disclaimers about even if it works today, it may n…