开发者

DDD - Enity Framework 4 and ncommon

开发者 https://www.devze.com 2023-01-20 05:32 出处:网络
I\'m trying to get EF4 working with ncommon 1.1 which provides DDD patterns such as UnitOfWork, Specification, Repository.

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.SetLocatorProvi开发者_运维知识库der(() => 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);
    }


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号