Hi all,
Filoject, a dependency injection framework for Ada, is now available.
What is this good for, you may ask?
I’m not claiming that Ada needs a DI framework, nor that it may even be a good idea to use one in Ada projects.
But given that practically all programming languages competing with Ada have DI frameworks, this may something which is worth experimenting with. Filoject is meant to provide a basis for this experimentation.
Filoject uses a code generator, a custom pragma and a custom aspect.
4 Likes
Well, plug-ins, to disclose the meaning of fancy buzz wording, were always possible in Ada without any frameworks. Tagged types and support of dynamically linked libraries is all one needs. You can load a dynamic library, derive a tagged type there from the a tagged type here, construct and pass whatever class-wide objects back and dispatch on primitive operations forth. It is almost trivial and works perfectly well. I have been using this technique in production code for decades.
So in a bad habit of answering rhetorical questions:
- Plug-in architectures are incredibly useful especially in long term projects (Ada’s main interest)
- No, no frameworks are needed, just GNAT compiler. Ada supports it out of the box.
And surely, contributions are welcome. Especially in the fields people are confused and thinking Ada as an outdated language etc…
It actually IMHO hasn’t that much to do with plugins - it’s more about a programming model where the application basically consists of a tree of objects, and instead of creating and connecting the objects you let the DI framework do the work.
Now, often these objects are singletons and in the case of Ada, there may be little reason to use such an architecture - using packages is the simpler and more straightforward approach.
However, things may be different if the objects are not singletons. For example, in a web application, you might want to have a tree of objects per session. And here, a DI framework could actually make sense.
It looks same to me. But anyway.
Um, this is more than trivial in Ada:
Generic
with Function Dependency( Stuff : Other_Stuff ) return Result;
with Procedure Combine( Object : in out Result; Parameters : Other_Stuff );
Function Example( Primary_Data : Whatever; Secondary_Data : Other_Stuff ) return Result;
See?
Nope. The obvious requirement is that you add a dependency at run-time. Example: load a new device driver. Generics cannot do that fundamentally.
Furthermore, if compile time were fine then that would be bad design because static dependencies can be expressed in Ada in many much clearer ways.