I am trying to improve my programming skills and knowledge and I have been doing some reading about various design patterns and youtubing videos etc.
One subject I thought was interesting was about Singletons being an
Anti-pattern which has lead me on to a problem that I am not quite sure how to solve. Allow me to explain.
Lets say I have created a GPS class library. In the library I have a class called
GpsSensorUtil. This class does everything to do with processing GPS data such as working out speed, distance etc and fires events with this information.
So now I'm thinking hey, maybe I want to see the GPS info visually. So I create a
UserControl in the library which will listen to the events of the
The issue I am thinking about is how can I wire up the
GpsSensorUtil to the
UserControl so that the
UserControl can listen to Events from the
In a normal application I would be looking into
DependancyInjection maybe with
Unity, but then I would need to find a way of initialising and configuring the
UnityContainer as there is no entry point in a class library.
I did think of creating like a singleton to be a static reference for the container but as I have been reading, this is not a good thing.
In my head the following needs considering.
GpsSensorUtildoes not know of the
UserControland does not need too.
UserControlerdoes not need to know of the
GpsSensorUtil, only the events it fires.
- Anyone could use this library so I don't want to constrain to one IoC like unity.
What's the best way to approach something like this?