You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When service is created and both factory and type is given then return type from factory is scanned instead of set type.
Steps To Reproduce
Simplified code just to illustrate dependencies between interface and classes.
There is interface for all repositories:
interface Repository {}
Concrete repository implementing interface:
class ArticleRepository implements Repository {
publicfunctioninjectService( Service$service ) {}
}
Factory for repositories implemented like this
class RepositoryFactory {
publicfunctioncreateRepository( string$table ): Repository {
if ( $table === 'articles' ) {
returnnewArticleRepository();
}
// Other repositores are created here ...
}
}
Then InjectExtension uses return type of RepositoryFactory::createRepository() (interface Repository) instead of type given in setType() from service definition (class ArticleRepository). So method ArticleRepository::injectService() is not found and added to generated DI container.
Expected Behavior
Expected result is that type from service definition should have priority over return type from factory.
With current state there is no way to override detected value.
Possible Solution
Problem is related to fix of issue #218.
When nette/di 3.0.1 is used then InjectExtension behaves as expected.
Another workaround is removal of return type from RepositoryFactory::createRepository().
The text was updated successfully, but these errors were encountered:
Version: 3.0.3
Bug Description
When service is created and both factory and type is given then return type from factory is scanned instead of set type.
Steps To Reproduce
Simplified code just to illustrate dependencies between interface and classes.
There is interface for all repositories:
interface Repository {}
Concrete repository implementing interface:
Factory for repositories implemented like this
Register service in extension
Current Behavior
Then InjectExtension uses return type of
RepositoryFactory::createRepository()
(interfaceRepository
) instead of type given insetType()
from service definition (classArticleRepository
). So methodArticleRepository::injectService()
is not found and added to generated DI container.Expected Behavior
Expected result is that type from service definition should have priority over return type from factory.
With current state there is no way to override detected value.
Possible Solution
Problem is related to fix of issue #218.
When nette/di 3.0.1 is used then InjectExtension behaves as expected.
Another workaround is removal of return type from
RepositoryFactory::createRepository()
.The text was updated successfully, but these errors were encountered: