-
Notifications
You must be signed in to change notification settings - Fork 3
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
Do you think automatic registration could be implemented? #6
Comments
First of all, sorry for being so late answering you @chuano. I'm not 100% sure about what are you asking for. I guess that you would like to be able to use DIOD's container without the need of registering every service. For example, instead of doing this: const builder = new ContainerBuilder()
builder.register(Mailer).use(AcmeMailer)
builder.register(UserRepository).use(SqliteUserRepository)
builder.registerAndUse(SignUpUseCase)
const container = builder.build()
const signUpUseCase = container.get(SignUpUseCase) To just do this: const builder = new ContainerBuilder()
const container = builder.build()
const signUpUseCase = container.get(SignUpUseCase) Am I right? I think that this would be impossible, because in that example I am using abstractions and not only class implementations. But it could exist the possibility to automagically register all the services if they all are class implementations. I mean, instead of doing this: const builder = new ContainerBuilder()
builder.registerAndUse(AcmeMailer)
builder.registerAndUse(SqliteUserRepository)
builder.registerAndUse(SignUpUseCase)
const container = builder.build()
const signUpUseCase = container.get(SignUpUseCase) To just do this, I think it could be possible: const builder = new ContainerBuilder()
const container = builder.build()
const signUpUseCase = container.get(SignUpUseCase) As you said importing all the classes is necessary, but in this example it is supposed that the import { Service } from 'diod'
import { SqliteUserRepository } from './SqliteUserRepository'
import { AcmeMailer } from './AcmeMailer'
@Service()
export class SignUpUseCase {
constructor(
private readonly userRepository: SqliteUserRepository,
private readonly mailer: AcmeMailer
) {}
execute(userData: UserDto): void {
const user = this.userRepository.create(userData)
this.mailer.sendConfirmationEmail(user)
}
} So, let me know if this example is what you are looking for (I'm assuming you are using Typescript). In that case, I will investigate and see what can I do. |
I'm interested about your last example, I was trying to implement it but It couldn't be possible |
It would be great to be able to automatically register all services that have the decorator.
As far as I know, it is not possible to do this because the meta-data is not generated without importing the classes, but maybe there is a way and I don't know it.
If you know any way in which we can approach this, I would like to collaborate with it. Just give me some clue and I'll start investigating.
Thanks.
The text was updated successfully, but these errors were encountered: