K
Kjetil Bjerknes
I'm currently creating some user controls in C#, and I've come across
the interface IServiceProvider. This interface must be one of the
worst examples of bad design I've ever seen. It contains one single
method, with the following signature:
object GetService(Type serviceType);
Can anyone tell be what this method is supposed to do? OK, I can see
that it's supposed to return a "service", but what exactly is a
service? According to the method signature it can be absolutely
everything, and the interface could just as well be called
IObjectRetriever.
To make matters worse, this interface is implemented/extended by a
number of classes and other interfaces, and none of them seem to think
it's important to inform what kind of services they return!
Why not create the following interface while we're at it, and let
every object implement it . Then we wouldn't need to add all those
stupid methods with descriptive names:
public interface IIronicTask {
object DoIronicTask(int taskID, object[] args);
}
__Please__ enlighten me if you're able to see the usefulness of
IServiceProvider! Or even better, if you know of some way to learn
what services it can provide. For now I'm particularly interested in
services that can be returned from ISite.GetService(),
Component.GetService() and the IServiceProvider parameter of
UITypeEditor.EditValue().
As a side note: It seems that System.ComponentModel.Component does not
implement IServiceProvider, however it does have a GetService()
method(?). The more I get into C# and the class library, words like
inconsistent and unintuitive seems to spring to mind a bit to often.
</KB>
the interface IServiceProvider. This interface must be one of the
worst examples of bad design I've ever seen. It contains one single
method, with the following signature:
object GetService(Type serviceType);
Can anyone tell be what this method is supposed to do? OK, I can see
that it's supposed to return a "service", but what exactly is a
service? According to the method signature it can be absolutely
everything, and the interface could just as well be called
IObjectRetriever.
To make matters worse, this interface is implemented/extended by a
number of classes and other interfaces, and none of them seem to think
it's important to inform what kind of services they return!
Why not create the following interface while we're at it, and let
every object implement it . Then we wouldn't need to add all those
stupid methods with descriptive names:
public interface IIronicTask {
object DoIronicTask(int taskID, object[] args);
}
__Please__ enlighten me if you're able to see the usefulness of
IServiceProvider! Or even better, if you know of some way to learn
what services it can provide. For now I'm particularly interested in
services that can be returned from ISite.GetService(),
Component.GetService() and the IServiceProvider parameter of
UITypeEditor.EditValue().
As a side note: It seems that System.ComponentModel.Component does not
implement IServiceProvider, however it does have a GetService()
method(?). The more I get into C# and the class library, words like
inconsistent and unintuitive seems to spring to mind a bit to often.
</KB>