question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to "transfer" resolved instances from a container to another?

See original GitHub issue

I want to achieve the following.

  1. On a worker thread, an ExportProvider resolves one single type and calls one method to retrieve data. E.g.:
var dataLoader = MiniContainer.GetExportedValue<IDataLoader>();
dataLoader.RetrieveData();
  1. Meanwhile, on the UI thread, the app’s ExportProvider resolves all exported types and values. I.e. regular bootstrapping.

  2. When the main container is ready, I want to “transfer” the IDataLoader instance from the worker thread. That way, the main container can load super-fast.

How can this be achieved? I guess this operation would be equivalent to “as soon as type X is resolved, call X.Foo() in a worker thread, then wait for it after bootstrapping”.

Please advise 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
weltkantecommented, Aug 16, 2019

Yes that works, another way to solve it is to not put IDataLoader into the catalog at all. You can have an IDataLoaderProvider in the catalog which will do all the async background stuff, and when its done it publishes the IDataLoader by making it available to others. Everyone would import the IDataLoaderProvider and access the IDataLoader through it, and you can decide how to handle “early access” (eg. blocking, async/await, events, etc.)

0reactions
AArnottcommented, Aug 16, 2019

So the basic idea is to explicitly set the value of an export

Explicitly set the value on an exporting property, yes. After which, any access to that property getter will of course return the value you set it to. That means when MEF accesses that property to get its exported value, it will get the value you set it to. It also means that if MEF accesses that property before you set it, MEF will get the default value instead and assign that to the importer that wanted it. This is the huge limitation of this air-lifting technique. You’d have to be very careful to not activate any MEF part that imports this value until the export has been set.

preventing the framework from retrieving its value from reflected constructor?

I don’t know what you mean by this. You’re not preventing the framework from anything.

Read more comments on GitHub >

github_iconTop Results From Across the Web

5 ways to move Docker container to another host
1. Export and import containers · 2. Container image migration · 3. Save and load images · 4. Migrate data volumes · 5....
Read more >
Copying data between Docker containers
To copy files from the host to a container one can use the `docker exec` command available since Docker 1.3.0. If have a...
Read more >
How to Transfer/Move a Docker Image to Another System?
Moving a Docker image to another system is easy. Use "docker save" to export the image as a TAR file, transfer it to...
Read more >
Migrate your Applications to Containers at Scale
Deploy a worker node as an Amazon Elastic Compute Cloud (Amazon EC2) instance. This will include a compatible operating system, which will take ......
Read more >
Copy an Amazon EC2 instance
It's not possible to transfer existing instances or AMIs between AWS accounts. Instead, you can manually migrate an EC2 image from one AWS...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found