Pass httpcontext to WCF via Castle Windsor

54 views
Skip to first unread message

mtols

unread,
Sep 26, 2011, 2:00:50 AM9/26/11
to Castle Project Users
We are trying to inject the current http context (so we can get
authentication info, e.g the forms authentication etc...) from our
asp.net mvc web site into our service constructors. Our services are
WCF and we are using by Castle Windsor at the client and service
layer. Is it possible to do this entirely from configuration? Does any
one know the best way to go about this?

Jason Meckley

unread,
Sep 26, 2011, 11:59:07 AM9/26/11
to castle-pro...@googlegroups.com
container.Register(Component.For<HttpContext>().Lifecycle.Transient().UsingFactoryMethod(kernel => HttpContext.Current));
I would use a set of adapters to abstract the http context. this way you are not fully dependent on the context. example

interface ICurrentUser
{
    string UserName {get;}
    bool IsInRole(string role);
}

class CurrentUser : ICurrentUser
{
    public HttpContext Context {get;set;}
    
    public string UserName {get{ return Context.User.Identity.Name;}}
    public bool IsInRole(string role)
    {
            return Context.User.IsInRole(role);
    }
}

something similar can be done for request, response, session, etc.
Reply all
Reply to author
Forward
0 new messages