开发者

Convention over configuration and the making the user's own convention

i am doing convention based coding where if u want a module then just you have to derive from the interface called IModule . And i will find all the Modules by scanning then in the runtime and will form the URL out of it.

In this case i have to register my URL with the name of the class(something like Asp.net MVC) by removing the Convention for Eg: if u have a CustomerModule i will remove the Module and register your URL as "/Customer". But i want to give the flexiblity for the user to change that Convention .

if (instance.Name.EndsWith开发者_JAVA百科("Module")) -- this is filter
{
  int instanceCount = instance.Name.IndexOf("Module"); -- action
  routeCollection.Add(new RouteDefination(instance.Name.Remove(instanceCount)));
}

The user can give any filter and the i need to take the action accordingly.. How can i do it .I can use expression or if u have any design patten . it will be very helpful


Provide a method/property in the interface that provides a readonly name.

public interface IModule
{
    /* other methods */
    string Alias { get; }
}

Or follow Java's approach with Servlets and allow user's to specify an XML file that you parse and allow overrides that way (e.g., <module name="CustomerModule" alias="Picky" />). Or both.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜