-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to use @Transactional() annotation to entire service (apply to all methods) #41
Comments
Hi @herbertpimentel, PR would be happily accepted... |
I extended the export interface TransactionalOptions {
propagation: Propagation
isolationLevel: IsolationLevel
}
const TransactionalService = (options: TransactionalOptions): ClassDecorator => {
return (target: Function) => {
for (const key of Object.getOwnPropertyNames(target.prototype)) {
const methodDescriptor = Object.getOwnPropertyDescriptor(target.prototype, key)
// assumes that only async methods need a transaction
const isAsyncMethod =
methodDescriptor &&
methodDescriptor.value instanceof Object.getPrototypeOf(async function() {}).constructor
if (!methodDescriptor || !isAsyncMethod) {
continue
}
Transactional(options)(target, key, methodDescriptor)
Object.defineProperty(target.prototype, key, methodDescriptor)
}
}
} It only adds transactions to @odavid Should this be a feature of the lib itself? How could I go about implementing it? |
Hey @cassinaooo, Can you please open a PR for that decorator? For this code to be added, I believe we need:
Let me know what you think... |
@odavid Is there a way for the Then we just need to decide on the override semantics instead of implementing a new decorator. I don't really have anything against |
@cassinaooo - I believe reflect metadata should help listing methods that are decorated with I believe you can start without the ignore feature. It was just a suggestion, since setting Hope it helps... |
@odavid I see and agree with your point. What should be expected of I'm trying to understand how Suppose we have a class annotated with |
Just weighing in here since I would like to see this. It seems to me that @transactional would always override @TransactionalService for defined options, and use the options declared in @TransactionalService as defaults. At least, that would be my personal expectation. As an additional alternative to a decorator like @NotTransactional(), perhaps @TransactionalService could also take an array of method names to exclude, eg:
|
Agree with @mscottnelson |
I'll try and submit a PR in the next few days. Thanks for your inputs @mscottnelson! I'll will follow your suggestion of |
give us a possibility to anotate the entire service class as transactional instead of only methods. and then apply it to each method of the service class;
The text was updated successfully, but these errors were encountered: