views:

29

answers:

1

I'm trying to get EF4 working with ncommon 1.1 which provides DDD patterns such as UnitOfWork, Specification, Repository.

The NCommon configuration line is throwing the following Exception:

SynchronizationLockException occurred

Object synchronization method was called from an unsynchronized block of code.

The actual code throwing the error is:

.ConfigureData<EFConfiguration>(config => config.WithObjectContext(() => new CoreContext(connectionString)))

Here is the code that I am running.

private static void ConfigureIoc()
    {
        var container = new UnityContainer();
        var serviceLocator = new UnityServiceLocator(container);
        ServiceLocator.SetLocatorProvider(() => serviceLocator);

        container
            .RegisterType(typeof(IUnitOfWorkScope), typeof(UnitOfWorkScope), new InjectionConstructor())
            .RegisterType(typeof(IList<>), typeof(List<>), new InjectionConstructor())
            .RegisterType<IVerticalRepository, EfVerticalRepository>()
            ;

        const string connectionString = 
               @"metadata=res://*/Core.csdl|res://*/Core.ssdl|res://*/Core.msl;provider=System.Data.SqlClient;provider connection string="";Data Source=devdatabase;Initial Catalog=InfoChoiceAdmin;Persist Security Info=True;User ID=sa;Password=sa;MultipleActiveResultSets=True""";

        var adapter = new UnityContainerAdapter(container);

        NCommon.Configure.Using(adapter)
            .ConfigureState<DefaultStateConfiguration>()
            .ConfigureData<EFConfiguration>(config => config.WithObjectContext(() => new CoreContext(connectionString)))
            .ConfigureUnitOfWork<DefaultUnitOfWorkConfiguration>(config => config.AutoCompleteScope());

        Ioc.Initialize(serviceLocator);
    }
A: 

David,

Could you post the exact stack trace of the exception? What I suspect is there's something strange going on during the object context's construction.

In NCommon when you call config.WithObjectContext(() => new CoreContext(connectionString)), it is internally creating an instance of the context to inspect it's MetadataWorkSpace. If you could also provide me with a repro sample it would help track down this issue.

Thanks.

Ritesh Rao
System.Threading.SynchronizationLockException occurred Message=Object synchronization method was called from an unsynchronized block of code. Source=Microsoft.Practices.Unity StackTrace: at Microsoft.Practices.Unity.SynchronizedLifetimeManager.TryExit() in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\Lifetime\SynchronizedLifetimeManager.cs:line 109 InnerException:
David See
Thanx for your help Ritesh, I ended up deleting the project and re-loading from SVN and it all worked.
David See