How to have ContainerScoped injection outside of ContainerContext?

In Droidium, there is abstraction of AndroidDevice via which I am doing almost anything with Android. I am producing AndroidDevice as ContainerScoped somewhere in StartContainer where I have container context.

In order to be able to have multiple Android devices in one test run, it obviously needs multiple abstractions of AndroidDevices.

This would not be problem if I interacted with AndroidDevice only in situations where I have container context. e.g while I am deploying and undeploying stuff to / from Android - Arquillian would give me “right” Android device injection according to which container context I am currently in.

The problem is that when Drone is about to destruct itself, the destruction is done somewhere in AfterClass but not in container undeployment phase where container context is activated and I would be good.

I am also using other helper classes which has AndroidDevice as runtime dependency and even these can be ApplicationScoped and have container scoped Android device in it (as a reference) so I am ok, I have problems when it comes to use these classes outside of container context in connection with multiple Android devices as is done in case of Selendroid destruction bound to Drone destruction which occurs outside of container context.

With existence of upcomming deployment scoped Drones, it would be possible to force Drones to destruct on BeforeUnDeploy so I would have right AndroidDevice however that means I would need to use @Drone @OperatesOnDeployment WebDriver everywhere …

Is there any better approach how to switch between container scoped android devices outside of container context?

The WebDriver instance created by Drone does not have access to the AndroidDevice internally?

Possible we would need to add support for @Disposes T

It doesn’t have that access, additionally, that WebDriver is instantiated just before it is used due to “lazy initialization” and I am sure that does not happen in ContainerContext at all.

Class scoped Drones are prepared / configured in BeforeClass and method scoped Drones in Before - no active container context in both cases.

However it is good idea.

I was thinking about some custom register to which I would put device(s) and list of deployment names it acts upon so when it comes to pull Android device outside of container context while doing some packaging stuff, I would provide deployment as a key and device would be a value (or vice versa) …

Could you elaborate that @Disposes idea? Where it would be put?

On top of my head it could work as a callback when a Context is destroyed.

Something like:

public class MyObserver {

	@Inject @TestScoped
	private InstanceProducer<T> tInst;

	public void create(@Observes Before event) {
		tInst.set(new T());

	// Called when the @TestScoped Context is destroyed..
	public void cleanup(@Dispose T t) {