473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

IServiceProvider. Why does this interface exist?

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>
Nov 16 '05 #1
2 21097

it doesn't mean much by itself, but it's part of the .NET lightweight container implementation. the lightweight container is basically a plugin architecture. the VS IDE uses this quite heavily

----- Kjetil Bjerknes wrote: ----

I'm currently creating some user controls in C#, and I've come acros
the interface IServiceProvider. This interface must be one of th
worst examples of bad design I've ever seen. It contains one singl
method, with the following signature

object GetService(Type serviceType)

Can anyone tell be what this method is supposed to do? OK, I can se
that it's supposed to return a "service", but what exactly is
service? According to the method signature it can be absolutel
everything, and the interface could just as well be calle
IObjectRetriever

To make matters worse, this interface is implemented/extended by
number of classes and other interfaces, and none of them seem to thin
it's important to inform what kind of services they return

Why not create the following interface while we're at it, and le
every object implement it :). Then we wouldn't need to add all thos
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 o
IServiceProvider! Or even better, if you know of some way to lear
what services it can provide. For now I'm particularly interested i
services that can be returned from ISite.GetService()
Component.GetService() and the IServiceProvider parameter o
UITypeEditor.EditValue()

As a side note: It seems that System.ComponentModel.Component does no
implement IServiceProvider, however it does have a GetService(
method(?). The more I get into C# and the class library, words lik
inconsistent and unintuitive seems to spring to mind a bit to often
</KB>
Nov 16 '05 #2
Kjetil,

See inline.

"Kjetil Bjerknes" <kb@trollsoft.com> wrote in message
news:1f**************************@posting.google.c om...
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.
A "service" here is functionality that the site provides which might not
necessarily be implemented by the container itself. For example, say that
the container offers a logging service. If the id (in this case the type)
for the "service" is well known, then the site can return the "service"
(read: object) that provides the expected functionality. Expecting the site
itself prevents the architecture from being pluggable.

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!
I agree with you here. It would be helpful if there was an extra method
indicating the services that it provides. Since the number of services it
provides are potentially limitless, it is impossible to cycle through all
the known types, passing them to GetService to see what returns null and
what does not.

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().
IServiceProvider is very, very valuable if you want to actually enable
the idea of a pluggable architecture. I think you bring up a good point
about being able to provide a list of ^what^ services it provides.

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.
GetService is meant as a helper method for classes that derive from
Component. It basically gets the site from the component and calls
GetService from that. It's shorthand for:

(this.Site == null ? null : this.Site.GetService(type));

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com


</KB>

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
11
by: Jon Smith via DotNetMonster.com | last post by:
Hi all, I'm new to C# and am practising the language by writing simple contact manager programmes. I'm having a problem using ADO. I'm trying to connect to an Access 2000 database using...
1
by: Simon Jefferies | last post by:
Hello, I'm writing a managed c++ project and have the following error:- error C2872: 'IServiceProvider' : ambiguous symbol could be 'c:\Program Files\Microsoft Visual Studio...
0
by: gerry.brennan | last post by:
Hi, I have a project which accesses a database via a database interface class which uses #include microsoft library. In the header file for this database class I have a prototype which...
6
by: phnimx | last post by:
I'm attempting to migrate a predominately MFC application that I've just inherited from Visual Studio.NET 2003 to Visual Studio 2005. I've managed to clean up a myriad of compile and link errors...
19
by: Angus | last post by:
I have a socket class CTestClientSocket which I am using to simulate load testing. I create multiple instances of the client like this: for (int i = 0; i < 5; i++) { CTestClientSocket* pTemp...
9
by: Jonathan Wood | last post by:
I found the following class on the Web: public class LoginRewriter : IHttpModule { void IHttpModule.Dispose() { } void IHttpModule.Init(HttpApplication app) { app.AuthorizeRequest += new...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
0
by: dakshayini | last post by:
Hi, I have created one project in Visual studio 2005. For my application i need to put Sleep() function.n i have added the #include <windows.h> Now if i run this i am getting error as'...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.