Skip to content

Allow us to pass a factory of FirebaseAppConfig to AngularFireModule.initializeApp() #1314

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

Closed
snakenstein opened this issue Oct 27, 2017 · 11 comments

Comments

@snakenstein
Copy link

snakenstein commented Oct 27, 2017

It would be great if we get an option to pass a factory function of FirebaseAppConfig to AngularFireModule.initializeApp().
In some cases such as using a webpack to get enviroment variables and AOT compiler it is impossible now to initialize AngularFireModule with correct config parameters. This is because of webpack does not run yet at the moment of module compilation.
The ability to pass a factory of FirebaseAppConfig to static initialization function would be a solution for this and maybe other similar problems.
One related issue already exists: #1281

@davideast
Copy link
Collaborator

@snakenstein I really like this idea. Would you like to post an API proposal?

@ippeiukai
Copy link

ippeiukai commented Dec 6, 2017

Something like this?

class AngularFireModule {

  // AngularFireModule.initializeAppWithDependency(
  //   [MyOwnConfig], 
  //   (ownConfig) => ownConfig.getFirebaseConfig(), 
  //   (ownConfig) => ownConfig.getFirebaseAppName()
  // )
  static initializeAppWithDependency(dep: any[], configFactory: Function, appNameFactory: Function): ModuleWithProviders {
    /* 
          { provide: FirebaseAppConfigToken, dep: dep, useFactory: configFactory },
          { provide: FirebaseAppName, dep: dep, useFactory: appNameFactory }
    */
  }

}

@snakenstein
Copy link
Author

snakenstein commented Dec 7, 2017

Yes, something like what @ippeiukai have suggested.
Actually, I am using this wrapper class as a workaround for now:

export class Angularfire2WorkaroundConfigModule {
    static initializeApp(configFactory: () => FirebaseAppConfig, appNameFactory: () => string) {
        return {
            ngModule: AngularFireModule,
            providers: [
                {provide: FirebaseAppConfigToken, useFactory: configFactory},
                {provide: FirebaseAppName, useFactory: appNameFactory}
            ]
        };
    }
}

@juristr
Copy link

juristr commented Jan 28, 2018

Thinking of this, it would also be cool if we could get rid of the compile-time configuration and get the Firebase config at runtime, like via some call to a config JSON (I recently wrote an article on that).

The point is when I'm creating a CD pipeline I'd like to build once and then move that same package from testing, staging to production environment, without the need of rebuilding my Angular app again. That obviously doesn't work when you use the Angular CLI environment.<env>.ts approach. Rather, I'd like to fetch it via a config using an approach like Angular's APP_INITIALIZER.

@jnorkus
Copy link

jnorkus commented Feb 14, 2018

@juristr I actually followed your article as example of run-time configuration but running into exactly same issue with Firebase. Do you have any kind of workaround for the time being?

@juristr
Copy link

juristr commented Feb 14, 2018

@jnorkus 😅I ran into this when working on a personal project. For now I don't have a workaround, as I didn't continue the last week working on it. And probably this week neither. Once I have a way to go around this I'll let you know 😄.

The main reason I'd like to get these runtime configs is for avoiding to re-build my app when moving between the CD pipeline stages.

Apparently right now the best way is to instantiate all the parts manually...but that's something I'd like to avoid. We'll see..

@jamesdaniels
Copy link
Member

We now allow runtime DI in rc7. Will document but give it a shot in the meantime.

@juristr
Copy link

juristr commented May 4, 2018

Awesome, thx. Will try it 👍

@brendonwm
Copy link

Does anyone have an example of how to "pass a factory of FirebaseAppConfig to AngularFireModule.initializeApp()" or alternative solution using runtime DI? Thanks.

@david-bulte
Copy link

Hi @jamesdaniels Is this now possible? I cannot find anything in the docs?

@nsanitate
Copy link

@jamesdaniels can you show us how runtime DI works with a snippet?

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

9 participants