Using Ncqrs fail when I tried to save second field
This is the error: Precondition failed.: !IsConfigured Cannot configure the environment when it is already configured.
public static void BootUp()
{
var config = new StructureMapConfiguration((i) =>
{
i.For&开发者_如何转开发lt;ICommandService>().Use(InitializeCommandService());
i.For<IEventStore>().Use(InitializeEventStore());
i.For<IEventBus>().Use(InitializeEventBus());
});
NcqrsEnvironment.Configure(config);
}
I have troubles when I tried to add new data, it allows me to create just one customer, but if I tried to add the seconde it fails:
NcqrsEnvironment.Configure(config);
Im using Ncqrs.
if (!NcqrsEnvironment.IsConfigured)
NcqrsEnvironment.Configure(config);
You should add the line tho check if it is already configured and if it is not, then should configure it.
How are you calling the BootUp() Method?
The documentation example on the NCQRS website has BootUp() called from a static contructor which is guaranteed to only be called once.
However if you're not calling BootUp() from a static constructor, be aware the "IsConfigured" value is not thread safe, and you could still experience your original exception if two or more threads try to execute BootUp() at in parallel which is very likely in a production environment.
Either implement a thread safe check, or run it from a static contructor to be on the safe side.
You can also use the Ncqrs.Environment.DeConfigure()
method. This is something I had to do for a web app running under Nancy, since Nancy currently creates a new IoC container with almost every request.
If I simply check IsConfigured it would have two separate configurations which would know nothing about each other.
精彩评论