title: Passing dynamic object to an angular module's forRoot()
body: <p>I'm using the package <code>ngx-cookieconsent</code> which imports the module as:</p>
  
  <p><code>const cookieConfig: NgcCookieConsentConfig = {
    "cookie": {
      "domain": "localhost"
    },
    ...
    "theme": "block",
    "content": {
      "policy": "Cookie Policy"
    }
  };
  ...
  @NgModule({
   imports: [
      NgcCookieConsentModule.forRoot(cookieConfig)
    ]</code></p>
  
  <p>However, the domain property on the config will be set at runtime and so I can't have this defined as a constant. To get round this I have done the following:</p>
  
  <p>Created a <code>ConfigurationService</code> that gets the config and stores it:</p>
  
  <pre><code>@Injectable()
  export class ConfigurationService {
  
    private configuration: IServerConfiguration;
  
    constructor(private http: HttpClient, @Inject('BASE_URL') private baseUrl: string) { }
  
    loadConfig() {
      return this.http.get&lt;IServerConfiguration&gt;(this.baseUrl + 'Configuration')
        .pipe(
          tap(config =&gt; {
            this.configuration = &lt;IServerConfiguration&gt;(config);
          })
        )
        .toPromise();
    }
  
    public domain(): string {
      return this.configuration.domain;
    }
  }
  </code></pre>
  
  <p>And this is set up as an <code>APP_INITIALIZER</code> so that the config is called first:</p>
  
  <pre><code>export function loadConfiguration(configService: ConfigurationService) {
    return () =&gt; configService.loadConfig();
  }
  
  ...
   providers: [
      ConfigurationService,   
      {
        provide: APP_INITIALIZER,
        useFactory: loadConfiguration,
        multi: true,
        deps: [ConfigurationService]
      }],
  </code></pre>
  
  <p>And then have created a class to create my cookieConsentOptions object using the config:</p>
  
  <pre><code>@Injectable()
  export class CookieConstentService {
  
    cookieDomain: string;
  
    constructor(configService: ConfigurationService) {
      this.cookieDomain = configService.domain();
    }
  
    get cookieConstentOptions(): NgcCookieConsentConfig {
      return {
        "cookie": {
          "domain": this.cookieDomain
        },
        "position": "top-right",      
        "content": {
          "message": "This website uses cookies to ensure you get the best experience on our website."
        }
      };
    }
  </code></pre>
  
  <p><strong>Issue</strong></p>
  
  <p>I've got the dependency set up between the configService and the CookieConstentService so that I only create the the cookie options when I have the config values.</p>
  
  <p>However, I am unsure how to pass a dynamic value to the <code>.forRoot()</code> of a module. I should be able to do <code>cookieConsentService.cookieConstentOptions()</code> to get the object but I'm not sure where to instantiate this to be used in he module import. It takes a dependency so can't just create a new instance myself.</p>
  
  <p>Any ideas how I effectively inject a method into a 3rd party module's <code>forRoot()</code>?</p>
  
  <p>Thanks </p>