Different (parallel) configurations (profiles?)

12 views
Skip to first unread message

Marc Gravell

unread,
Feb 19, 2009, 4:42:34 PM2/19/09
to structuremap-users
I *think* that this is related to the "profiles" feature - but I
simply can't get profiles to work, either through xml or through code
(I get errors claiming that there is no profile, even though I created
it).

What I ideally want is to be able to define the *standard* (/default)
types, and then for a range of different named configurations,
override some of the settings - i.e. if I had

global: IFoo => Foo, IBar => Bar
configA: (no changs)
configB: IFoo => SpecialFoo

I believe this could map to 2 containers, loaded using named profiles.
The purpose being that if I ask either container for an IBar, I get a
Bar - but configA returns a Foo (for IFoo), where-as configB returns a
SpecialFoo.

Can somebody give me a clue how I can configure this? Either xml or
code is fine... I just want it to work. All I need is interface-to-
concrete-type mappings (no special config/property settings).

Any hints? Much appreciated,

Marc Gravell

dpurrington

unread,
Mar 5, 2009, 1:27:16 PM3/5/09
to structuremap-users
Marc:

I've been able to achieve this, where I have a Registry with defaults,
and then use multiple Profiles as overrides. I did have some issues
with a Profile wiping out another one (it seems you can only use one
at a time), but never had the problem of getting errors using the
profile. It sounds like your problem is more basic. I think you're
supposed to create your profile on the Registry. In mine, I followed
this pattern:

public const string ProfileA = "ProfileA";
public const string ProfileB = "ProfileB";
public MyRegistry()
{
/* multiple DSL statements for defaults */
ForRequestedType<...>...

/* create the profiles */
CreateProfile(ProfileA)
.For<...>
CreateProfile(ProfileB)
.For<...>

/* etc */
}

Then later:

Container.SetDefaultsToProfile(MyRegistry.ProfileA);

Works for me.

--Dave

Michael Smith

unread,
Mar 5, 2009, 4:36:45 PM3/5/09
to structure...@googlegroups.com
It looks as though the problem is that you cannot have an EMPTY
profile. I was able to recreate the error.

My setup had two profiles specified (test and dev) with the default
assumed to be prod, When I made this explicit by creating an empty
Profile:

CreateProfile("Prod");

I, er, got an empty profile exception. :-)

The hackish solution I came up with, considering I want my Prod
profile to use all the defaults was:

CreateProfile("Prod")
For<ServiceA>().UseConcreteType<ServiceA>();

Cheers,
Michael

2009/3/5 dpurrington <dave.pu...@gmail.com>:

Marc Gravell

unread,
Mar 7, 2009, 11:43:22 AM3/7/09
to structuremap-users
Indeed - the problem was the *empty* profile problem. The answer (for
me) was to introduce a dummy interface/implementation.

http://stackoverflow.com/questions/566506/configuring-profiles-with-structuremap

Marc
Reply all
Reply to author
Forward
0 new messages