Unity Factory and Unit Of Work Pattern

Dec 3, 2009 at 12:34 AM

Hi all

I am having tough time to use unity with the Unit of work pattern.

I have a WorkItem class which class the DAL [UnitofWork class]. I also have a controllerfactory class that I creates a Workitem. So for every Workitem I have a UnitOfWork created. Hope that made sense

public class WorkItem : IWorkItem
    {
        IUnitOfWork _work;
        private Guid _workItemId = Guid.Empty;

        public Guid WorkItemId
        {
            get { return _workItemId; }
        }
        public WorkItem(IUnityContainer container)
        {
            _workItemId = Guid.NewGuid();
            _work = container.Resolve<IUnitOfWork>();

        }

        public void Commit() //implementation

        public void RollBack() // implentation

        public void Dispose // implementation

     }

 public class ControllerFactory
    {
        public static IWorkItem CreateWorkItem()
        {
            // HOW DO I CREATE THE WORK ITEM HERE
        }

    }

So how i create a the workItem here. I donot have access to the unity container in my controllerfactory. Help appreciated.

Also, can I do IWorkItem item = new WorkItem(container) ????  Like can i actually pass container as parameter to the constructor ? I am thinking no, but ...?

 

 

 

Dec 5, 2009 at 7:22 AM

Take a look at the StaticFactoryExtension

http://www.pnpguidance.net/Post/RegisteringFactoryMethodCreateObjectsUnityStaticFactoryExtension.aspx

Dec 8, 2009 at 1:48 AM

Hi

Thanks for info. But it is resolving the same instance everytime. I need a new instance