-
Notifications
You must be signed in to change notification settings - Fork 37
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
Question: Scoped Containers and "default" connection #51
Comments
Full reproduction repo HERE |
Ok after some fun debugging last night I found the issue. The current TypeDI integration sets the ConnectionManager service for use by TypeORM, but doesnt set it as a global type. When we are in a scoped container, TypeDI goes through the below steps:
//...
typedi_1.Container.registerHandler({
object: object,
index: index,
propertyName: propertyName,
value: containerInstance => getRepositoryHelper(connectionName, repositoryType, entityType, containerInstance),
});
function getRepositoryHelper(connectionName, repositoryType, entityType, containerInstance) {
const connectionManager = containerInstance.get(typeorm_1.ConnectionManager);
if (!connectionManager.has(connectionName)) {
throw new manager_not_found_error_1.ConnectionNotFoundError(connectionName);
}
get(identifier) {
const globalContainer = container_class_1.Container.of(undefined);
const globalService = globalContainer.findService(identifier);
const scopedService = this.findService(identifier);
if (globalService && globalService.global === true)
return this.getServiceValue(globalService); //*1
if (scopedService)
return this.getServiceValue(scopedService);
if (globalService && this !== globalContainer) { //*2
const clonedService = { ...globalService };
clonedService.value = empty_const_1.EMPTY_VALUE;
this.set(clonedService);
const value = this.getServiceValue(clonedService); //*3
this.set({ ...clonedService, value });
return value;
}
if (globalService)
return this.getServiceValue(globalService);
throw new service_not_found_error_1.ServiceNotFoundError(identifier);
} Changing the initial TypeDI Container.set to set ConnectionManager as global: true fixes all of this as it would then return that global service as found in //*1 @NoNameProvided @pleerock |
PR #53 |
@NoNameProvided @pleerock, any input on this? |
@Xzas22 any work around on this? I'm facing the same issue |
My work around was unfortunately to drop TypeORM until this got traction... |
Gonna go ahead and drop another BUMP here as I think now more than every this package needs some attention. I did submit a PR with this change. See #53 |
out of curiosity, rather than dropping TypeORM altogether did you consider dropping this package / the TypeDI integration and just manually resolving your repositories? That's where I'm thinking about going currently. TypeDI seems pretty stable, and TypeORM seems at least actively used. |
Trying to follow the below guideline from #39:
Originally posted by @NoNameProvided in #39 (comment)
and I get the new serviceNotFound: MaybeConstructable error. So I try using the Container exported from typeorm-typedi-extensions, and I get the "cannot get connection default" error.
Any guidance here on how to properly use scoped containers with TypeORM & TypeDI?
The text was updated successfully, but these errors were encountered: