예제 #1
0
파일: Config.cs 프로젝트: attila3453/alsing
        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
파일: Config.cs 프로젝트: attila3453/alsing
 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
파일: Config.cs 프로젝트: attila3453/alsing
        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);
        }