Customizing Wolfringo
Wolfringo is designed with customizability from ground up. It achieves it mainly thanks to heavy use of Abstractions and Dependency Injection. Constructors of both WolfClient and CommandsService take an IServiceProvider to resolve their dependencies, and WolfClientBuilder and CommandsServiceBuilder have special methods for registering/overwriting services. This allows you to replace most components of Wolfringo without having to clone and recompile it yourself!
Check navigation menu for guides how to customize specific parts of Wolfringo.
Replacing WolfClient dependencies
To replace any of WolfClient dependencies, use With...
commands on the builder.
_client = new WolfClientBuilder()
.WithResponseTypeResolver<MyResponseTypeResolver>()
// alternatively, factory and instance patterns are also allowed
//.WithResponseTypeResolver(provider => new MyResponseTypeResolver())
//.WithResponseTypeResolver(_responseTypeResolver)
.Build();
Replacing CommandsService dependencies
To replace any of CommandsService dependencies, use With...
commands on the builder.
_client = new WolfClientBuilder()
// ... client config ...
.WithCommands(commands =>
{
commands
.WithArgumentsParser<MyArgumentsParser>()
// alternatively, factory and instance patterns are also allowed
//.WithArgumentsParser(provider => new MyArgumentsParser())
//.WithArgumentsParser(precreatedCustomResolver)
})
.Build();
IDisposable services
Your custom service can implement IDisposable - both WolfClient and CommandsService handle disposable services depending on how they were registered.
Service will be automatically disposed for you when WolfClient/CommandsService is disposing service was registered by either:
- using generic method (
WithResponseTypeResolver<MyResponseTypeResolver>()
; - using factory method (
WithResponseTypeResolver(provider => new MyResponseTypeResolver())
; - using Wolfringo.Hosting.
If service was registered using concrete type, or you didn't use WolfClientBuilder or CommandsServiceBuilder and opted to use constructors directly, you'll need to dispose these services manually.
This is because Wolfringo has no way to know whether you're using these services in other places - disposing them in such case would break your code.