Пример #1
0
        public static DomainContext GetBlogContext()
        {
            var dataContext = new Entities();
            
            var workspace = GetDomainWorkspace(dataContext);
            var persistedEventBus = GetPersistedEventBus();
            var messageBus = GetEarlyEventBus(dataContext, workspace, persistedEventBus);

            var context = new DomainContext(workspace,messageBus);

            return context;
        }
Пример #2
0
 private static MessageBus GetEarlyEventBus(Entities dataContext, IWorkspace workspace, MessageBus persistedEventBus)
 {
     var messageBus = new MessageBus();
     messageBus
         .AsObservable<IDomainEvent>()
         .Do(e =>
             workspace.Committing += (s, ea) =>
             {
                 ObjectStateEntry entry;
                 if (dataContext.ObjectStateManager.TryGetObjectStateEntry(e.Sender, out entry))
                 {
                     //resend the same event after commit
                     persistedEventBus.Send(e);
                 }
             })
         .Subscribe();
     return messageBus;
 }
Пример #3
0
        public static IWorkspace GetDomainWorkspace(Entities context)
        {                     
            Func<Type, object> selector = t =>
                {

                    if (t == typeof(MyBlog.Domain.Entities.Post))
                        return context.Posts;
                    
                    if (t == typeof(MyBlog.Domain.Entities.Comment))
                        return context.Comments;

                    if (t == typeof(MyBlog.Domain.Entities.Category))
                        return context.Categories;

                    return null;
                };

            return new EF4Workspace(context,selector);
        }