This question can seem odd but we really do have such cases where we need to fix constructor signature.
For example I want it for dependencies resolving in DI. And if constructor is extended and requires more parameters some of which are quite context dependent I'm in trouble.
Sure DI container will throw exception if it cannot resolve the dependency but this is not the best way I suppose.
I just refactor our application and understand that what initially planned to be a good candidate for DI is broken now due to deliberate constructor extension without understanding the consequences. The only way to stop it is just the convention between developers.
Language support would be very helpful but both C# and Java don't have it.
So I think there should be some reason for this feature is not implemented...Why?
Here is how our factory looks like:
public class EntityBase : IEntity
{
public EntityBase(IBusinessModel model, IAppContext context)
{
}
}
public class DescendatnEntity : EntityBase, IDescendatnEntity
{
public DescendatnEntity(IBusinessModel model, IAppContext context, ...additional params...)
{
}
}
public interface IEntitiesFactory
{
IEntity GetBaseEntity();
IDescendantEntity GetDescendantEntity(...those additional params...);
}
IBusinessModel
and IAppContext
singletons whereas additional params are transient.
In case where only caller knows the values of transient parameters there's no need for the factory to know about these params.