How to divide one large provider file into smaller providers?


#1

How do we divide one large provider file into smaller providers and have them become more modularized.

Like basicAuth Provider will be run first then the other providers(like post message) have basicAuth injected and ready to make their requests?


#2

You can inject providers into other providers just as you inject them into pages, but in this specific case I find it often best to do all authorization header munging in an HttpInterceptor, which means that none of the other providers have to care about it at all, as it’s wired up in the app module.


#3
export class pizzaDeliveryService extends BaseHttp {

    constructor(public storage: Storage, public http: Http) {
      super(storage, http);
    }

I used the inheritance and try to inherit the basehttp class which contains all the authorization, getting token and setting the sessionIDs etc… after that pizza delivery has all the other functions from baseHttps, but the sessionID is always empty after inheritance as a new instance is created. And dependency injection injects the provider to have a single instance I assume. How should I better implement this, I’m stuck on breaking this large provider into smaller ones


#4

I’m not a big fan of inheritance in general, and especially not for this situation. This post describes my general structure for implementing authorized HTTP in Angular apps: it consists of a token sink, an interceptor, and then a general business object provider that knows nothing of authorization aside from the fact that when it performs a successful login it has to tell the token sink “hey, here’s a new token”.