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
Originally posted by vnayar November 3, 2023
For context, when autowiring an instance that has already been pre-defined, the system avoids @Autowire for values that have already been set. This is very useful when adding fake components during testing.
// Test autowiring does not autowire member where instance is non-null
However, the same behavior is not seen for members that have the @Value annotation. Those values get re-initialized. Thus, if you have an autowired component, such as "MyAppConfig" or something like that with many @Value properties, and then I try to inject an existing instance in a test, e.g. container.register!MyAppConfig.existingInstance(testConfig);, when the rest of the code tries to resolve that dependency, the @Value annotations will be processed again, and replace any values set for the test.
Is this a bug, or is it intended behavior with a known workaround? Can you disable re-evaluation of @Value annotations for existing instances that have been plugged into the DependencyContainer?
The text was updated successfully, but these errors were encountered:
Discussed in #44
Originally posted by vnayar November 3, 2023
For context, when autowiring an instance that has already been pre-defined, the system avoids
@Autowire
for values that have already been set. This is very useful when adding fake components during testing.This is seen in the test here:
poodinis/test/poodinis/containertest.d
Line 148 in 87c036d
However, the same behavior is not seen for members that have the
@Value
annotation. Those values get re-initialized. Thus, if you have an autowired component, such as "MyAppConfig" or something like that with many@Value
properties, and then I try to inject an existing instance in a test, e.g.container.register!MyAppConfig.existingInstance(testConfig);
, when the rest of the code tries to resolve that dependency, the@Value
annotations will be processed again, and replace any values set for the test.Is this a bug, or is it intended behavior with a known workaround? Can you disable re-evaluation of
@Value
annotations for existing instances that have been plugged into theDependencyContainer
?The text was updated successfully, but these errors were encountered: