package com.netflix.appinfo.providers;

import com.netflix.appinfo.AmazonInfo;
import com.netflix.appinfo.Ec2EurekaArchaius2InstanceConfig;
import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.archaius.api.Config;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;

@Singleton
public class CustomAmazonInfoProviderInstanceConfigFactory implements EurekaInstanceConfigFactory {

    private final Config configInstance;
    private final Provider<AmazonInfo> amazonInfoProvider;
    private EurekaInstanceConfig eurekaInstanceConfig;

    @Inject
    public CustomAmazonInfoProviderInstanceConfigFactory(Config configInstance, AmazonInfoProviderFactory amazonInfoProviderFactory) {
        this.configInstance = configInstance;
        this.amazonInfoProvider = amazonInfoProviderFactory.get();
    }

    @Override
    public EurekaInstanceConfig get() {
        if (eurekaInstanceConfig == null) {
            eurekaInstanceConfig = new Ec2EurekaArchaius2InstanceConfig(configInstance, amazonInfoProvider);
        }

        return eurekaInstanceConfig;
    }
}

@@ -221,16 +221,63 @@
 .Config;
+%0Aimport com.netflix.discovery.DiscoveryManager;
 %0A%0Aimport
@@ -1101,16 +1101,169 @@
 ovider);
+%0A%0A            // Copied from CompositeInstanceConfigFactory.get%0A            DiscoveryManager.getInstance().setEurekaInstanceConfig(eurekaInstanceConfig);
 %0A       

Fix DiscoveryManager for DI tests