I'm currently creating a fluent interface and I'm not 100% sure what's the best way to implement optional branches. A little example:
// Normal service registration
.AddService(myService)
// Service registration with additional parameters
.AddService(myOtherService).WithParameter(ServiceParam.Timeout, 100)
.AddService(myThirdService)
Now, I'm not really sure which return types AddService() and WithParameter() should have. The base interface provides AddService
which must returns something supporting WithParameter
AND AddService
. Would you recommend to have the following structure (pseudo-code):
interface FluentStart
{
AddService
}
interface FluentServiceConfiguration
{
WithParameter
}
and finally, AddService would return an interface of:
interface FluentStartORFluentServiceConfiguration
: FluentStart
, FluentServiceConfiguration
? Is there any other (better) way to do that?