473,545 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IServiceProvide r. Why does this interface exist?

I'm currently creating some user controls in C#, and I've come across
the interface IServiceProvide r. 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
IObjectRetrieve r.

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(in t taskID, object[] args);
}
__Please__ enlighten me if you're able to see the usefulness of
IServiceProvide r! 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.GetServic e(),
Component.GetSe rvice() and the IServiceProvide r parameter of
UITypeEditor.Ed itValue().

As a side note: It seems that System.Componen tModel.Componen t does not
implement IServiceProvide r, 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 21122

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 IServiceProvide r. 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
IObjectRetrieve r

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(in t taskID, object[] args)

__Please__ enlighten me if you're able to see the usefulness o
IServiceProvide r! 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.GetServic e()
Component.GetSe rvice() and the IServiceProvide r parameter o
UITypeEditor.Ed itValue()

As a side note: It seems that System.Componen tModel.Componen t does no
implement IServiceProvide r, 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.c om> wrote in message
news:1f******** *************** ***@posting.goo gle.com...
I'm currently creating some user controls in C#, and I've come across
the interface IServiceProvide r. 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
IObjectRetrieve r.
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(in t taskID, object[] args);
}
__Please__ enlighten me if you're able to see the usefulness of
IServiceProvide r! 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.GetServic e(),
Component.GetSe rvice() and the IServiceProvide r parameter of
UITypeEditor.Ed itValue().
IServiceProvide r 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.Componen tModel.Componen t does not
implement IServiceProvide r, 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.GetSe rvice(type));

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


</KB>

Nov 16 '05 #3

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

Similar topics

20
10100
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
7381
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 ADO.Net. When compiling I'm getting the following error : The type or namespace name 'ADO' does not exist in the class or namespace 'System')are you...
1
1739
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 8\VC\PlatformSDK\Include\ServProv.h(48) : System::IServiceProvider IServiceProvider' or 'stdafx.cpp : System::IServiceProvider'
0
1777
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 passes by reference a CRecordset paramater.
6
16161
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 but I'm stuck on one final problem. Please note that this application compiled/linked and ran just fine out of Visual Studio.NET 2003. Details:...
19
4170
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 = new CTestClientSocket(this, ip, port); pTemp->Connect(); m_collClients.push_back(pTemp);
9
1954
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 EventHandler(authorizeRequest); }
162
10103
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 prefix them with 2 underscores, but I hate prefixing my vars, I'd rather add a keyword before it. Python advertises himself as a full OOP language,...
0
2328
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' IServiceProvider' : ambiguous symbol Please if any one knows about this let me know.. Actually i have created in one more project with single form n if i...
0
7475
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7409
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7918
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7436
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7766
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5341
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.