Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • fabrice 104 posts 227 karma points
    Nov 11, 2014 @ 18:53
    fabrice
    1

    ServiceFactory

    Hello,

    Thanks for your package. I really liked your Service factory so I reused it in another project but with generic instead of creting a new property for each service :

    public static THelper GetHelper<THelper>() 
    {
        var key = string.Concat("factory-",  typeof(THelper).Name);
        if (!HttpContext.Current.Items.Contains(key))
            HttpContext.Current.Items.Add(key, (THelper) Activator.CreateInstance(typeof (THelper), new object[] {}));
        return (THelper)HttpContext.Current.Items[key];
    }

    And to use it :

    ServiceFactory.GetHelper<MyClass>().MyMethod();

    What do you thing of it ?

     

  • Lee 1114 posts 3048 karma points
    Nov 19, 2014 @ 15:43
    Lee
    100

    Like it! Thanks :) Will probably use that.

Please Sign in or register to post replies

Write your reply to:

Draft