Providers and Injections should be by name or at least by Map<string,type> and not by a simple Array<type>
- 主要語言
- TypeScript
- 星號
- 7.8k
- 分支
- 2.2k
- 平均合併
- 22 小時 28 分鐘
- 30 天內合併 PR
- 6
描述
### Version info
**Angular:** 14.2
**Firebase:** 9.9.3
**AngularFire:** 7.4.1
**Other (e.g. Ionic/Cordova, Node, browser, operating system):** Irrelevant
### Expected behavior
Provide / Injection by name or Map where the string is the name to find easy and clean your angular firebase components or have a function to findByName(name: string).
I'm not talking only about Auth, I'm talking regarding all your types but I use Auth for the examples
``` typescript
@NgModule({
imports: [
provideFirebaseApp(() => initializeApp(config)), // default app
provideFirebaseApp(() => initializeApp(config2, 'app2')),
provideFirebaseApp(() => initializeApp(config3, 'app3')),
provideAuth(() => getAuth()), // from default app
provideAuth(() => getAuth(getApp('app2'))),
provideAuth(() => getAuth(getApp('app3'))),
],
})
```
One of the next options should be there to be use it easy:
**Option 1** - Could be work with your actual Array but I think that search this search byName in this array is dirty and I recommend to not reinvent the wheel and use a Map
``` typescript
constructor(
private authApp: Auth,
private authApp2: AuthInstances.getByName('app2'),
private authApp3: AuthInstances.getByName('app3'),
) { }
```
**Option 2** - Could be work with your actual Array but again I recommend to not reinvent the wheel and use a Map
``` typescript
constructor(private authInstances: AuthInstances) { }
doWithAuth(name: string) {
const auth = this.authInstances.getByName(name)
// the things that you want to do with your auth
}
```
**Other options** - Any idea that let you select your angular fire element more easy and clean that now.
### Actual behavior
Provide / Injection is a simple Array and does not have any method to select by name.
``` typescript
@NgModule({
imports: [
provideFirebaseApp(() => initializeApp(config)), // default app
provideFirebaseApp(() => initializeApp(config2, 'app2')),
provideFirebaseApp(() => initializeApp(config3, 'app3')),
provideAuth(() => getAuth()), // from default app
provideAuth(() => getAuth(getApp('app2'))),
provideAuth(() => getAuth(getApp('app3'))),
],
})
```
``` typescript
private authMap: Map;
constructor(private authInstances: AuthInstances) {
this.authInstances.forEach(auth => {
this.authMap.set(auth.name,auth);
});
}
```
### Feedback
I think that your Provide / Injection should work with maps or with something that can be select the future injection by name.
Another important thing, is that you must declare a default app, if not the AuthInstaces fail because default app is not initializate and then to find this default app is so ugly `name: "[DEFAULT]"`
To finish, you cannot import only one auth if your auth is not default, because you have a way to import default and to import an array with default and another auths. Is there a way to inject `auth: Auth` by name and avoid import all the array?
Issue post from discussion: _Originally posted by @todosybuenrollo in https://github.com/angular/angularfire/discussions/1026#discussioncomment-3613308_
貢獻指南
研究方向
首先追蹤 issue 中描述的 provideFirebaseApp、provideAuth 和 AuthInstances 入口點,包括預設 Firebase 應用程式和具名 Firebase 應用程式的解析方式。在決定採用具名注入還是以 map 為基礎的 API 之前,先檢查目前的注入行為以及相關測試(如果有)。完成標準是:消費者可以依名稱選取非預設的 Auth 執行個體,而不必手動掃描陣列,同時保留預設應用程式的行為。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- angular, firebase, typescript
- 領域
- backend-api-design
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 28/100