Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upPrototype code for packet handler decorators #40
Conversation
|
|
||
| namespace Networker.Common | ||
| { | ||
| public abstract class PacketHandlerDecorator<T> : PacketHandlerBase<T> where T: class |
MarkioE
Mar 24, 2019
Owner
This particular way of doing it would work well as an extension project, but I would like to avoid the dependency on PacketHandlerBase as you are able to use just an IPacketHandler now.
Would this also mean you'd need a new PacketHandlerDecorator for each packet type?
This particular way of doing it would work well as an extension project, but I would like to avoid the dependency on PacketHandlerBase as you are able to use just an IPacketHandler now.
Would this also mean you'd need a new PacketHandlerDecorator for each packet type?
snarlynarwhal
Mar 24, 2019
•
Author
Contributor
Yeah implementing IPacketHandler makes more sense. The decorator has helper methods to get the target handler method info based on the packet type. This assumes the handler methods accept a base packet type though. I definitely need to think more about this.
Where should I wire up the decorators? Once I get it to a testable state, I can play around with ideas to make sure a single decorator can handle multiple packet types.
Yeah implementing IPacketHandler makes more sense. The decorator has helper methods to get the target handler method info based on the packet type. This assumes the handler methods accept a base packet type though. I definitely need to think more about this.
Where should I wire up the decorators? Once I get it to a testable state, I can play around with ideas to make sure a single decorator can handle multiple packet types.
MarkioE
Mar 27, 2019
Owner
I've got a new way of registering packets + handlers coming in soon which might be the best place to wire up the decorator, I'll let you know when it's ready.
I've got a new way of registering packets + handlers coming in soon which might be the best place to wire up the decorator, I'll let you know when it's ready.
snarlynarwhal
Mar 27, 2019
•
Author
Contributor
Alright sounds good! Also, it might be preferable to assign decorators using the builder instead of attributes. That approach would require a fluent interface instead of method chaining, which I can add later on if you think it's a good idea.
Alright sounds good! Also, it might be preferable to assign decorators using the builder instead of attributes. That approach would require a fluent interface instead of method chaining, which I can add later on if you think it's a good idea.
I wanted to get feedback before continuing with the last step of wiring up the decorators.
I added 3 classes to Networker:
Decorate[typeof(AuthorizationHandlerDecorator)][Authorize]The attributes can get added to handlers and modules.
I put together
Demo.Decoratorsto demonstrate how the features gets used. It does not function yet.The last part I need to do is wire up the decorators on startup. Should do this in
BuilderBase.SetupSharedDependencies?