DDD - Enity Framework 4 и ncommon - PullRequest
       42

DDD - Enity Framework 4 и ncommon

0 голосов
/ 15 октября 2010

Я пытаюсь заставить EF4 работать с ncommon 1.1, который предоставляет шаблоны DDD, такие как UnitOfWork, Specification, Repository.

Строка конфигурации NCommon выдает следующее исключение:

Произошло исключение SynchronizationLockException

Метод синхронизации объектов был вызван из несинхронизированного блока кода.

Фактический код, выдавший ошибку:

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

Вот код, который я выполняю.

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);
    }

1 Ответ

0 голосов
/ 18 октября 2010

David

Не могли бы вы опубликовать точную трассировку стека исключения? Я подозреваю, что во время создания контекста объекта происходит нечто странное.

В NCommon, когда вы вызываете config.WithObjectContext (() => new CoreContext (connectionString)), он внутренне создает экземпляр контекста для проверки его MetadataWorkSpace. Если бы вы могли также предоставить мне образец репродукции, это помогло бы отследить эту проблему.

Спасибо.

...