This may seem a little strange, but I really need to create a workaround for the very complex handling of duplex communications in C #, especially in order to get other developers to adhere to the DRY principle.
So what I am doing is to have a multi-standard based on a type that looks like this:
internal sealed class SessionManager<T> where T : DuplexServiceBase
which is not a problem at all - for now.
However, as soon as I want the services (I gather with one instance per session) to register with the SessionManager, problems begin:
internal abstract class DuplexServiceBase : MessageDispatcherBase<Action>
(MessageDispatcherBase is my class that creates a stream and sends messages asynchronously).
I want to have a method that looks like this:
protected void ProcessInboundMessage() {
... but the problem is, how can I get into the "me"?
I really need separate session managers for each class of service, because everyone has their own notifications (basically these are very annoying "NotifyAllClients" - a method that makes us want to pull my own hair in the last hours), and they need to be processed separately.
Do you have ANY ideas?
I do not want to use "AsyncPattern = true", btw ... this would require me to give up the type of security, to comply with the requirements of the contract (this will lead to very bad abuse of the communication system that I configure here), and this will require abandonment DRY principle, thereβs going to be a lot of repetitive code in all of this, and thatβs what I seriously frowned at.
Edit:
I found the best possible solution, thanks to the answers here - this is the EXTENSION METHOD, hehe ...
public static SessionManager<T> GetSessionManager<T>(this T sessionObject) where T : DuplexServiceBase { return SessionManager<T>.Current; }
I can use this as follows:
GetSessionManager().Connect(this);
Mission accomplished.: - D
This method (owned by DuplexServiceBase) gives me the session manager I want to work with. Fine!: -)