Themelia Pro A powerful new development platform built on ASP.NET.
 
Understanding Handler Factories
 
 

When registering HTTP handlers as Themelia Pro endpoint types, you simply place the name of the HTTP handler in the "type" attribute of the endpoint. However, when reusing an HTTP handler time and time again, or when shipping handlers via web components, it's recommended that you create a Handler Factory to ship with your handlers.

Keep in mind that handler factories are a completely separate concept than ASP.NET's HTTP handler factories. Themelia Pro handler factories are extremely simplified factory classes that accept a key and return an instantiated HTTP handler. The idea is simple: alias your custom handlers to make them easier to register and read.

Below is a sample HTTP handler in the Sample.Web assembly:

namespace Sample.Web
{
    public class AuthenticationHttpHandler : System.Web.IHttpHandler
    {
        //- @IsReusable -//
        public Boolean IsReusable
        {
            get { return true; }
        }
 
        //- @ProcessRequest -//
        public void ProcessRequest(System.Web.HttpContext context)
        {
            context.Response.Write("Hello");
        }
    }
}

This class registers may be registered to Themelia Pro as the following:

<themelia.web>
  <webDomains>
    <add>
      <endpoints>
        <add selector="contains" text="/authenticate/" type="Sample.Web.AuthenticationHttpHandler, Sample.Web" />
      </endpoints>
    </add>
  </webDomains>
</themelia.web>

While this is functional, it's not idea. The type is difficult to remember, needlessly long to type, and is prone to typos. Below is a much better version of the above registration:

<themelia.web>
  <webDomains>
    <add>
      <endpoints>
        <add selector="contains" text="/authenticate/" type="Authentication" />
      </endpoints>
    </add>
  </webDomains>
</themelia.web>

This shorter form is made possible through the use of a handler factory. A Themelia Pro handler factory is created by creating a class that implements the Themelia.Web.Processing.HandlerFactoryBase class. Below is a sample that corresponds to the above registration:

namespace Sample.Web
{
    public class SampleHandlerFactory : Themelia.Web.Processing.HandlerFactoryBase
    {
        //- @CreateHttpHandler -//
        public override IHttpHandler CreateHttpHandler(String text)
        {
            switch (text)
            {
                case "auth":
                case "authentication":
                    return new AuthenticationHttpHandler();
            }
            //+
            return null;
        }
    }
}

There is a one-to-many relationship between name and handler, thus, using this handler factory, you could also use the following endpoint configuration:

<themelia.web>
  <webDomains>
    <add>
      <endpoints>
        <add selector="contains" text="/authenticate/" type="Auth" />
      </endpoints>
    </add>
  </webDomains>
</themelia.web>

Handler factories, like all Themelia Pro factories, are registered in a web domain under the <factories> collection. For example:

<themelia.web>
  <webDomains>
    <add>
      <factories>
        <add type="Sample.Web.HandlerFactory, Sample.Web" />
      </factories>
    </add>
  </webDomains>
</themelia.web>

It's important to realize that HTTP handler factories are completely optional. However, they do increase the performance of your HTTP handlers. Without a handler factory, your handlers will be created dynamically whereas using a factory would allow them to be created in a more efficient way.

So, it's highly recommended that you always create a handler factory even if you have only one HTTP handler.