8000 TODO Do Not add Application to IOC Container. · Issue #3 · snytkine/bind-rest · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

TODO Do Not add Application to IOC Container. #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

Open
snytkine opened this issue Oct 18, 2020 · 0 comments
Open

TODO Do Not add Application to IOC Container. #3

snytkine opened this issue Oct 18, 2020 · 0 comments

Comments

@snytkine
Copy link
Owner
snytkine commented Oct 18, 2020

Avoid circular dependencies where Application has ref to container and container contains application
Why do we need application in container?

  1. We are getting settings from application to find out if schema validation has been enabled. But maybe we can instead create a settings component and then only add that component to Container.
    2.We can potentially inject the Application component with @Inject decorator into any component. But why and what are we achieving. It may have something to do with hot reloading of container.
    For hot reloading or hot adding a new component we need to do component scan, add a new component to container and then do we need to add new container to Application? If we do then yes, we need a way to grab ahold of the Application from component like from Controller. But there should be a better way.

Right now in application we have this code in handleRequest method:
const handlerPromise = this.middlewares.reduce((prev, next) => {
return prev.then(next);
}, Promise.resolve(ctx));

This means that we need access to sorted array of middlewares that we currently set in Application in this.middlewares = getMiddlewares(container);

Also setupRoutes(container); inside Application uses setupRouter function and it does not need access to Application, so this can be done outside of Application, possibly in some type of stand-alone initializer function.

First, can we do something like in React where they inject Application Context and you can grab ahold of context somehow?
Second, maybe we can just NOT REPLACE the create container with another one, maybe we can just reload the components and re-initialize existing container. That would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0