Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to use the IOC pattern and could not find the perfect way of implementing the state management using the same. Would be great if someone can help me with the same. Thank you.

share|improve this question
are you using Unity containers – saravanan May 12 at 12:17

1 Answer

What I would do is first create an Interface containing all the properties you would need to store in the Session (i.e.: the context):

using ProjectName.Core.Domain;

namespace ProjectName.Core.Interfaces
{
    public interface IProjectNameSessionContext
    {
        string StringProperty1 { get; set; }
        bool BoolProperty1 { get; set; }
        ProjectName.Core.Domain.Entity1 DomainEntity1 { get; set; }
    }
}

Then create a class that implements this interface, mark it as serializable:

using ProjectName.Core.Interfaces;

namespace ProjectName.Front.SessionData
{
    [Serializable]
    public class ProjectNameSessionContext : IProjectNameSessionContext
    {
        public string StringProperty1 { get; set; }
        public bool BoolProperty1 { get; set; }
        public ProjectName.Core.Domain.Entity1 DomainEntity1 { get; set; }
    }
}

And finally tell your IOC to bind the interface with the class at runtime an instantiate an object in HttpSession context.

It looks like this with StrucureMap:

For<Core.Interfaces.IProjectNameSessionContext>().LifecycleIs(new HttpSessionLifecycle()).Use<ProjectNameSessionContext>();

Hope that helps!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.