Click here to Skip to main content
Licence Ms-PL
First Posted 21 Aug 2007
Views 10,567
Bookmarked 15 times

Creating a managed service factory

By | 21 Aug 2007 | Article
Host any number of services, regardless of whether they are remote or local within a "Server" construct and access that server easily.

Introduction

I had a plan. I wanted to create a way of accessing services in multiple locations from any location. Each location could have one or more services which may be duplications or different. That is a really abstract way of thinking about it, but I eventually came up with a solution.

After using Reflector to view the Team Foundation Server source code, which gave me many pointers for which I would like to thank the TFS Team at Microsoft, I came up with the following solution:

image

This allows you to host any number of services, regardless of whether they are remote or local within a "Server" construct and to access that server easily. Remote and local services can exist side by side in the same server, for example, you could have an ActiveDirectoryClientService hosted in a ClientServer.

From the server level (IClientServer), you can request a service based on its type or on an interface that it implements. To achieve this, the IClientService interface has a property called contracts that loops through all of the interfaces that the client service object implements and pulls out only those interfaces that have the ClientServiceContractAttribute added to them. Thus, you need to make sure that all of your interfaces (e.g., ITeamServer) have that attribute regardless of whether it also has a ClientServiceContractAttribute.

From the factory level, you can again request either services by type or by implementation, but this request is cross server. If you have two servers added to the factory and they both implement different contracts, you can pull any one back you like. If both servers have the same implementation, you can choose whether you bring back the first or a random implementation. The potential for a load balancing solution is there, but not implemented.

Below is a diagram of my TFSEventHandlerServer that includes both local and remote services. For ease of development and because it is a common thing to do, I created the WcfClientServiceBase class that provides a number of features that allow less code to be written in the individual service client classes.

image

In this example, you can call any of the ClientServices with the same code:

Get the server with a call:

Dim Server As Servers.TFSEventHandlerServer
Server = Servers.ClientServerFactory.GetServer(Of Servers.TFSEventHandlerServer)_
         (New System.Uri(http://server:6873))

And get client services with the Subscriptions being a local service and TeamServers as a remote one.

Dim Subscriptions As Clients.SubscriptionsService
Subscriptions = Server.GetService(Of Clients.SubscriptionsService)()
Dim TeamServers As Clients.TeamServersService
TeamServers = Server.GetService(Of Clients.TeamServersService)()

As I hope, you can see this makes it easier to implement many features with an enterprise environment. All you have to know is what services are available where. There is also the possibility that a lookup service could be implemented that would allow the Factory to bring you services when you do not even know there they are!

I hope this helps those trying to find a way to achieve the same goals without being too restrictive. You can download the code from my CodePlex TFS Event Handler project.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

Martin Hinshelwood

Instructor / Trainer
Northwest Cadence
United States United States

Member

Follow on Twitter Follow on Twitter

Martin Hinshelwood is an Senior ALM Consultant at Northwest Cadence, but also a Microsoft Visual Studio ALM MVPs in Washington, US (Formally UK) and has over 9 years experience in the software industry. He is a member of the Visual Studio ALM Rangers and is also a Professional Scrum Trainer. He regularly writes on his Processes, Practices & Tools blog, and speaks often on Scrum, good practices and Visual Studio ALM.

 

Martin aims to provide Strategic and Tactical consulting on successful implementations of new Processes, Practices & Tools within both small and large organisations across the world. These would include, but not be limited to:

 
  • Scrum Mentoring & Training - Scrum Master Training, Scrum Developer Training, Scrum Mentoring, Scrum Coaching
  •  
  • Practice improvements – Requirements (Backlog,Limiting Work In Progress, Relative Complexity, Acceptance Criteria, Planning Poker, User Stories, Use Cases, Visualisation) , Teams (Team Protection, Commitment), Code (Unit Testing, Branching, Continuous Integration, TDD, ), Test (Acceptance Test Driven Development, Automation, ), Release & Configuration (Continuous Delivery, Continuous Deployment)
  •  
  • Visual Studio ALM Implementation, upgrades & Training - Visual Studio, Team Foundation Server, Team Foundation Build & Microsoft Test Manager


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 21 Aug 2007
Article Copyright 2007 by Martin Hinshelwood
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid