-3

I'm new to DotNet CORE, I would like to know if there is any way I can force different applications in my environment to implement a common interface.

More specifically I would like every new application that enters the system to be forced to implement an onLoad() function that would register them in my "application registry"?

Edit: Considering that I have a main dashboard application, that "aggregates" and shows information about other applications (as long as they are registered in the "application registry"). What I meant by "entering the system" is the process to register itself. And my problem is that in my "application registry" I do not have the knowledge that what is being registered implements certain things I want them to implement.

Thanks :)

rodrigo
  • 1
  • 1
  • Use the Interface as argument type in your code. That is actually what they are there for - enforcing that certain things are implemented. Without colliding with the single inheritance rule. – Christopher Nov 16 '19 at 20:38
  • 2
    Please expand on the context of your question. What do you mean by “application that enters the system”? – Jessica Nov 16 '19 at 20:56

1 Answers1

-1

This sounds like a case for Interfaces or Inheritance.

Interfaces can be easily implemented by every class. So it is in no way disruptive to a class to follow your requirements. It can be easily expected from a user of your code. For example, the List class implements a half-dozen interfaces. Just because code using it might need that code from it.

If you want to make sure everything handed into your classes has a certain function, make a interface:

public interface loadable{
    public void onLoad();
}

And then use loadable as the type in your Function parameters.

If you need more then 1 Interface, you have to implement this via a generic paramter that has multiple Interfaces in the where clause, as described here:

https://stackoverflow.com/a/4073492/3346583

Christopher
  • 9,634
  • 2
  • 17
  • 31