Skip to content
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

Set container context with static method, so it is not required to pass context to Container.defaultContainer method #136

Open
Steven-Chan opened this issue Jun 13, 2017 · 2 comments

Comments

@Steven-Chan
Copy link
Contributor

Steven-Chan commented Jun 13, 2017

Reason:
context passed to defaultContainer is useless after the first time called and the container is initialized.

This can reduce code repetitiveness, and can be used without context, which is actually useless most time.

New API

Container

public static Container defaultContainer() { ... }
public static void configure(Context context, Configuration config) { ... }

Usage

Current

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        Configuration config = new Configuration.Builder()
                .endPoint("https://<your-app-name>.skygeario.com/")
                .apiKey("<your-api-key>")
                .build();

        Container.defaultContainer(this).configure(config);
    }
}

// somewhere else inside an Activity
Container.defaultContainer(this).callLambdaFunction(...);

Proposed

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        Configuration config = new Configuration.Builder()
                .endPoint("https://<your-app-name>.skygeario.com/")
                .apiKey("<your-api-key>")
                .build();

        Container.configure(this, config);
    }
}

// somewhere else inside an Activity
Container.defaultContainer().callLambdaFunction(...);

Considering compatibility,

// these are still valid
Container.defaultContainer(this);
Container.defaultContainer(this).configure(config);

// this will throw exception, if Container.configure not called before
Container.defaultContainer();
@rickmak
Copy link
Member

rickmak commented Aug 2, 2017

I think this is no longer valid after the new API grouping?

@Steven-Chan
Copy link
Contributor Author

@rickmak This is still valid actually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants