Search code examples
c#asp.net-mvcstructuremapstructuremap3

cannot resolve symbol SetAllProperties in StructureMap.Net4


In my project i am using structureMap.Net4 (version 3.0.3) with StructureMap (3.0.3) . I configured the Ioc with following code for setter injection

public static IContainer Initialize()
        {

            ObjectFactory.Initialize(x =>
                        {





                            x.For<ICacheManager>().Use<MemmoryCacheManager>();
                            x.SetAllProperties(y => y.OfType<ICacheManager>);
                            //x.ForConcreteType<AuthorizationManager>()
                            //    .Configure.Setter<ICacheManager>(y => y.CacheManager)
                            //    .IsTheDefault();
                        });
            return ObjectFactory.Container;
        }

But i am getting an error cannot resolve symbol SetAllProperties . i already referenced this following namespace

using StructureMap;
using StructureMap.Graph;

Why i am getting this error ? how i can solve this ? or should i reference any other namespace


Solution

  • StructureMap 3 has changed where Setter Injection is configured. It is now configured using a PolicyExpression, it can be accessed at ConfigurationExpression.Policies. I've attached a sample below.

    ObjectFactory.Configure(x =>
    {
        x.Policies.SetAllProperties(y => y.OfType<ICacheManager>());
    });