CDCgov / trusted-intermediary

Bringing together healthcare providers by reducing the connection burden.
Apache License 2.0
11 stars 5 forks source link

@Inject for Non-Singleton Classes #1361

Open jorg3lopez opened 2 months ago

jorg3lopez commented 2 months ago

Situation:

At the moment, we use the @Inject annotation for only singleton classes. This is because the ApplicationContext class only registers singleton classes. These classes are later scanned and have the instances injected, of the objects that use the @Inject annotation.

Proposed Solution:

Have the non-singleton classes be able to use the @Inject annotation to inject the instances of classes that have been registered into the ApplicationContext.

Reference:

https://flexion.slack.com/archives/C055XTF22B0/p1688582573819939

Food for Thought:

Create a method in the ApplicationContext that will take in the non-singleton object that has the @Inject annotations. This should be part of the constructor of the non-singleton objecct. It should call the method in the ApplicationContext and pass itself as the parameter. The ApplicationContext will scan this class and inject the instances for the objects using @Inject. This is an example of how it can be accomplished.

jorg3lopez commented 4 days ago

Draft RP created