Skip to content

Implement IServiceManager interface - #7946

Merged
sharadkjaiswal merged 1 commit into
DynamoDS:masterfrom
sharadkjaiswal:services
Jun 10, 2017
Merged

sharadkjaiswal merged 1 commit into
DynamoDS:masterfrom
sharadkjaiswal:services

Conversation

@sharadkjaiswal

@sharadkjaiswal sharadkjaiswal commented Jun 9, 2017 •

Copy link
Copy Markdown
Contributor

Purpose

This PR provides a mechanism to register and retrieve service objects via IExtensionManager interface to provide some custom functions. Implements a new interface IServiceManager and IExtensionManager inherits this interface.

/// <summary>
/// Defines a mechanism for registering and retrieving a service object; 
/// that is, an object that provides custom support to other objects.
/// </summary>
public interface IServiceManager : IServiceProvider
{
       /// <summary>
       /// Allows extension applications to register some specific service by its type.
       /// Only one service of a given type can be registered.
       /// </summary>
       /// <typeparam name="T">Type of the service</typeparam>
       /// <param name="service">The service object to register</param>
       /// <returns>A key for the registered service if registeration is 
       /// successful else null.</returns>
       string RegisterService<T>(T service);

       /// <summary>
       /// Unregisters a service of given type registered with given key. 
       /// </summary>
       /// <typeparam name="T">Type of the service</typeparam>
       /// <param name="serviceKey">The service key to ensure that only authorized
       /// client is unregistering this service type.</param>
       /// <returns></returns>
       bool UnregisterService<T>(string serviceKey);

       /// <summary>
       /// Gets the service object of the specified type.
       /// </summary>
       /// <typeparam name="T">Type of the service</typeparam>
       /// <returns>The service object if registered else null</returns>
       T Service<T>();
}

Declarations

Check these if you believe they are true

  • The code base is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning, and are documented in the API Changes document.

Reviewers

@mjkkirschner

FYIs

@ikeough
@pboyer

@sharadkjaiswal
sharadkjaiswal merged commit c14de9b into DynamoDS:master Jun 10, 2017
@sharadkjaiswal
sharadkjaiswal deleted the services branch June 10, 2017 01:53
@mjkkirschner

Copy link
Copy Markdown
Member

@sharadkjaiswal what is this going to be used for?

@sharadkjaiswal

Copy link
Copy Markdown
Contributor Author

@mjkkirschner many times some services are implemented in Extension application library and we don't have a good consistent way to access those services. For example, if we want to access PackageLoader from any other library we need to know the name of PackageManager extension application and then iterate over all extensions to get the extension with matching name from extension manager and then cast it to PackageManagerExtension to finally get to PackageLoader.
We could now define an interface for PackageLoader and keep it at DynamoService.dll and then access it directly from the ExtensionManager service API.

@sharadkjaiswal

Copy link
Copy Markdown
Contributor Author

@mjkkirschner please look at PR #7963 for a reference use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants