1

Please consider the following codes

private static void InitializeStructureMap()
        {
            ObjectFactory.Initialize(x =>
            {
                x.For<IUnitOfWork>().Use<MyContext>();

                x.For<IUserService>().Use<UserService>();
                x.For<IProductService>().Use<ProductService>();
            });


             x.Policies.SetAllProperties(

                    y =>
                    {
                        y.OfType<IUnitOfWork>();
                        y.OfType<IUserService>();
                        y.OfType<IProductService>();
                    });
        }

namespace TestApp
{
    public partial class Frm1 : BaseForm
    {
        public IUnitOfWork Uow { get; set; }
        public IUserService UserService { get; set; }
        public IProductService ProductService { get; set; }

        public Frm1()
        {
            InitializeComponent();
        }
    }
}

When I debug the above code, I realized that (Uow , UserService.Uow , ProductService.Uow )object instances are the same instance. But PerRequest is StructureMap default life cycle, So why are they same instance ?

ramin_rp
  • 321
  • 1
  • 4
  • 14

0 Answers0