views:

30

answers:

1

Structure map (2.6).

I have some classes and a registry that look like the following:

public interface IManyType {}
public class ManyType1 : IManyType {}
public class ManyType2 : IManyType {}
public class ManyType3 : IManyType {}

public class TestRegistry : Registry
    {
        public TestRegistry()
        {
            For<IManyType>().Add<ManyType1>();
            For<IManyType>().Add<ManyType2>();

            Profile("Profile1").For<IManyType>().Use<ManyType1>();
            Profile("Profile1").For<IManyType>().Use<ManyType2>();
            Profile("Profile1").For<IManyType>().Use<ManyType3>();
        }
    }

What I've found is that whether or not I've set the profile on ObjectFactory, SM will return all three instances. If it's not clear, what I'm after is registering a different set of instances for a given type using profiles.

Am I doing something wrong?

-Joe

A: 

That syntax should work, although it is deprecated, here is the current syntax:

Profile("Profile1", p => p.For<IManyType>().Use<ManyType1>()

Then of course you have to switch to the profile like so:

container.SetDefaultsToProfile("Profile1");
Robin Clowers
CreateProfile(...) is not a part of the 2.6 syntax.
jbenckert