1

I have an ASP.Net Web Forms project, which is built as (among other things) a user interface to a CRM web service.

I have an interface, IMembershipService, which exposes a number of methods for purchasing different kinds of subscriptions to a service. The concrete implementation of this, SpecificMemberService, will abstract a number of web service calls to a third-party CRM system.

The concrete implementation requires that different 'subscription levels' be passed to it as specific 4-character string codes. Currently, I have defined the following in my service layer:

public static class MemberTypes
{
    public const string Basic = "MEM1";
    public const string Extra = "MEM2";
    public const string Professional = "MEM3";
}

However, these codes are specific to the concrete class SpecificMemberService and - as such - shouldn't really be independent of it as they currently are. How can I expose strongly-typed MemberType codes to my web application, which are constant with respect to a concrete implementation of IMembershipService?

4

1 回答 1

2

创建一个 MemberType 接口。向您的服务接口添加一个GetMemberTypes方法,该方法公开一个IMemberType.

public interface IMemberType {      
    public string Name { get; set; } // i.e. "Professional"
    public string Code { get; set; } // i.e. "MEM3"
}

public void ClientCode() {

    // Instantiate a concrete service (calling a factory would be even better).
    IMembershipService service = new MembershipService();

    // Get the list of MemberTypes exposed by the concrete MembershipService.
    Collecton<IMemberTypes> types = service.GetMemberTypes();

    // Subscribe to service defined in IMembershipService with "Professional" level, if possible.
    foreach (IMemeberType type in types) {
        if ((type.Name == "Professional"))
            service.SubscribeToAwesomeService(type.Code);
    }
}

将“专业”公开为常量或枚举以获得奖励积分。

于 2013-03-21T22:07:10.557 回答