Giter Site home page Giter Site logo

Comments (4)

abeckus avatar abeckus commented on June 10, 2024

Thanks for the suggestion, one of us will look into this.

Alan

from atf.

abeckus avatar abeckus commented on June 10, 2024

At point the [ExportMetadata("Order", ...)] is not used for controlling initialization order. It is declared in Atf.Wpf section which is work in progress.
Generally MEF does a pretty good job of negating the need to explicit control the order.
In some cases IPartImportsSatisfiedNotification can be used for component that obtain dependencies via [Import] instead of [ImportingConstructor]

Thanks
Alan

from atf.

Ron2 avatar Ron2 commented on June 10, 2024

Hi Jelle,

That usage of ExportMetadataAttribute in ATF was inadvertent. One of our clients uses it, but we did not copy over the mechanism that looks at that attribute. The sorting mechanism would be very similar to this post:
http://stackoverflow.com/questions/1770297/how-does-mef-determine-the-order-of-its-imports

I don’t think we should use this ExportMetadataAttribute in ATF in this way. There are a variety of ways to control the initialization order that are more obvious and lower-maintenance than having a numerical explicit order on the component.

• You can implement MEF’s IPartImportsSatisfiedNotification, which has the OnImportsSatisfied() method. This method will get called by MEF when all of the imports have been satisfied.
• Your component’s IInitializable.Initialize() method will be called after composition, and so all of the objects in the TypeCatalog will have been created, and then you can do further initialization.
• You can have lazy imports, to get around a circular dependency. For example: [ImportMany] private IEnumerable<Lazy<IDocumentClient>> m_documentClients = null;
• You can override AtfApp’s OnCompositionBeginning() to acquire certain types of objects from your CompositionContainer, to make sure that certain objects are initialized first.
• You can override AtfApp’s OnCompositionComplete() to do last-minute initialization of certain objects.

Can you please try some of the above ways? If these are not sufficient, then we can try to support ExportMetadataAttribute with an “Order” property and an integer value. Otherwise, I’d like to remove that one usage.

--Ron

from atf.

JelleVM avatar JelleVM commented on June 10, 2024

Hi Ron and Alan,

Thanks for your answers. I think one of those solutions might be the right one, but I need to delve into it a bit more.

Let me outline the problem, to give a bit more context. I am using the CommandServiceExtension, which is extremely useful for binding to commands directly from XAML. The only problem is that this XAML is part of an import. In the CommandServiceExtension class, it is required that the Composer and the CommandService be imported and ready, and to actually use it, your command has to be imported already too. The nasty thing about a MarkupExtension is that ProvideValue() is only ever called once and then never more, so if any of the aforementioned required imports haven't happened yet, the command binding will be invalid forever.
Hence my need for the import order.

I think forcing those to be loaded OnCompositionBeginning() might work, to it'd be a hacky way. IPartImportsSatisfiedNotification isn't going to help here, methinks. Perhaps I can make all my XAML Lazy loads indeed, but I'd have to check if my application allows that.

All the best!
Jelle

from atf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.