Skip to content

New explicit registration method of component in the ObjectFactory

Hugo edited this page Aug 7, 2024 · 1 revision

Since #4429, a new registration method in the ObjectFactory is introduced to allow explicit components registration.

Why this this change

Main goal is to remove both

  • the ObjectFactory singleton (once this API will be spread to the entire code base)
  • the implicit registration of objects while loading dynamic libraries (plugins)

What error would I get with my plugin

Soon, warnings will let you know that you should move to the new API.

  • a compile-time warning Implicit object registration is deprecrated since v24.06. Check #4429 for more information.
  • a run-time warning: [ObjectFactory] PLUGINNAME has already registered its components. or a error of component creation COMPONENT not created

How to apply this new API to my plugin

#4858 demonstrates the changes to conduct in all modules and plugins (this specific commit)

  • replace the old component registration API call (which was using core::RegisterObject())
  • add a call to the new register function in the function void registerObjects(sofa::core::ObjectFactory* factory) of the plugin init.cpp

Any question 👉 post on GitHub Discussions referencing this page

Temporary compatibility layer

The legacy RegisterObject mechanism is preserved and will warn the user at the compilation and at run-time.

Clone this wiki locally