Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ enum Scope {
*/
Default, //

/**
* A new instance of the bean is created the first time it is needed in an
Comment thread
smaugho marked this conversation as resolved.
* Activity scope, it is then retained and the same instance is always returned
* from within the same Activity. Different Activities hold different copies of
* the bean.
*/
Activity,

/**
* A new instance of the bean is created the first time it is needed in a
* Fragment scope, it is then retained and the same instance is always returned
* from within the same Fragment. Different Fragments hold different copies of
* the bean.
*/
Fragment,

/**
* A new instance of the bean is created the first time it is needed, it is then
* retained and the same instance is always returned.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2016-2019 the AndroidAnnotations project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.api.bean;

public interface BeanHolder {

<T> T getBean(Class<T> key);

<T> void putBean(Class<T> key, T value);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2016-2019 the AndroidAnnotations project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.test.ebean;

import org.androidannotations.annotations.EBean;

@EBean(scope = EBean.Scope.Activity)
public class ActivityScopedBean {
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,29 @@ public class BeanInjectedActivity extends Activity {
@Bean
public SomeSingleton singletonDependency;

@Bean
public ActivityScopedBean activityScopedDependency;

@Bean
public FragmentScopedBean fragmentScopedDependency;

public EmptyDependency methodInjectedDependency;
public SomeSingleton methodInjectedSingleton;
public SomeInterface methodInjectedInterface;
public SomeSingleton methodInjectedSingleton;
public ActivityScopedBean methodInjectedActivityScoped;
public FragmentScopedBean methodInjectedFragmentScoped;

public EmptyDependency annotatedParamDependency;
public SomeSingleton annotatedParamSingleton;
public SomeInterface annotatedParamInterface;
public SomeSingleton annotatedParamSingleton;
public ActivityScopedBean annotatedParamActivityScoped;
public FragmentScopedBean annotatedParamFragmentScoped;

public EmptyDependency multiDependency;
public SomeSingleton multiDependencySingleton;
public SomeInterface multiDependencyInterface;
public SomeSingleton multiDependencySingleton;
public ActivityScopedBean multiDependencyActivityScopedBean;
public FragmentScopedBean multiDependencyFragmentScopedBean;

@Bean
protected void injectDependency(EmptyDependency methodInjectedDependency) {
Expand All @@ -60,6 +72,16 @@ protected void injectSingleton(SomeSingleton methodInjectedSingleton) {
this.methodInjectedSingleton = methodInjectedSingleton;
}

@Bean
protected void injectActivityScope(ActivityScopedBean methodInjectedActivityScoped) {
this.methodInjectedActivityScoped = methodInjectedActivityScoped;
}

@Bean
protected void injectFragmentScope(FragmentScopedBean methodInjectedFragmentScoped) {
this.methodInjectedFragmentScoped = methodInjectedFragmentScoped;
}

protected void injectDependencyAnnotatedParam(@Bean EmptyDependency annotatedParamDependency) {
this.annotatedParamDependency = annotatedParamDependency;
}
Expand All @@ -72,10 +94,20 @@ protected void injectSingletonAnnotatedParam(@Bean SomeSingleton annotatedParamS
this.annotatedParamSingleton = annotatedParamSingleton;
}

protected void injectActivityScopedAnnotatedParam(@Bean ActivityScopedBean annotatedParamActivityScoped) {
this.annotatedParamActivityScoped = annotatedParamActivityScoped;
}

protected void injectFragmentScopedAnnotatedParam(@Bean FragmentScopedBean annotatedParamFragmentScoped) {
this.annotatedParamFragmentScoped = annotatedParamFragmentScoped;
}

protected void injectMultipleDependencies(@Bean EmptyDependency multiDependency, @Bean(SomeImplementation.class) SomeInterface multiDependencyInterface,
@Bean SomeSingleton multiDependencySingleton) {
@Bean SomeSingleton multiDependencySingleton, @Bean ActivityScopedBean multiDependencyActivityScopedBean, @Bean FragmentScopedBean multiDependecyFragmentScopedBean) {
this.multiDependency = multiDependency;
this.multiDependencyInterface = multiDependencyInterface;
this.multiDependencySingleton = multiDependencySingleton;
this.multiDependencyActivityScopedBean = multiDependencyActivityScopedBean;
this.multiDependencyFragmentScopedBean = multiDependecyFragmentScopedBean;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ public class CustomFragment extends Fragment {
@Bean
SomeBeanWithRootFragmentWithDifferentFragment someBeanWithDifferentFragment;

@Bean
ActivityScopedBean activityScopedBean;

@Bean
FragmentScopedBean fragmentScopedBean1;

@Bean
FragmentScopedBean fragmentScopedBean2;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (C) 2016-2019 the AndroidAnnotations project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.test.ebean;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EFragment;

import android.app.Fragment;

@EFragment
public class CyclicBeansFragment extends Fragment {

@Bean
SomeCyclicSingletonA singletonA;

@Bean
SomeCyclicSingletonB singletonB;

@Bean
SomeCyclicActivityScopedA cyclicActivityScopedA;

@Bean
SomeCyclicActivityScopedB cyclicActivityScopedB;

@Bean
SomeCyclicFragmentScopedA cyclicFragmentScopedA;

@Bean
SomeCyclicFragmentScopedB cyclicFragmentScopedB;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@
*/
package org.androidannotations.test.ebean;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EFragment;

import android.app.Fragment;

@EFragment
public class DifferentFragment extends Fragment {

@Bean
ActivityScopedBean activityScopedBean;

@Bean
FragmentScopedBean fragmentScopedBean;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2016-2019 the AndroidAnnotations project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.test.ebean;

import org.androidannotations.annotations.EBean;

@EBean(scope = EBean.Scope.Fragment)
public class FragmentScopedBean {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2016-2019 the AndroidAnnotations project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.test.ebean;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;

@EBean(scope = EBean.Scope.Activity)
public class SomeCyclicActivityScopedA {

@Bean
SomeCyclicActivityScopedB activityScopedB;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2016-2019 the AndroidAnnotations project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.test.ebean;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;

@EBean(scope = EBean.Scope.Activity)
public class SomeCyclicActivityScopedB {

@Bean
SomeCyclicActivityScopedA activityScopedA;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2016-2019 the AndroidAnnotations project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.test.ebean;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;

@EBean(scope = EBean.Scope.Fragment)
public class SomeCyclicFragmentScopedA {

@Bean
SomeCyclicFragmentScopedB fragmentScopedB;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2016-2019 the AndroidAnnotations project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.test.ebean;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;

@EBean(scope = EBean.Scope.Fragment)
public class SomeCyclicFragmentScopedB {

@Bean
SomeCyclicFragmentScopedA fragmentScopedA;

}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.