Beispiel #1
0
        public CodeNamespace Build(List <DomainClass> domainClasses)
        {
            _nameSpaceBuilderUtil.WithName($"{_nameSpace}").WithDomain().WithEfCore();
            foreach (var domainClass in domainClasses)
            {
                _nameSpaceBuilderUtil.WithDomainEntityNameSpace(domainClass.Name);
            }

            var nameSpace = _nameSpaceBuilderUtil.Build();

            var eventStore = _classBuilderUtil.Build("EventStoreContext");

            eventStore.BaseTypes.Add(new CodeTypeReference("DbContext"));

            var properties = new List <Property>();

            properties.Add(new Property {
                Name = "EventHistory", Type = $"DbSet<{new DomainEventBaseClass().Name}>"
            });
            foreach (var domainClass in domainClasses)
            {
                properties.Add(new Property {
                    Name = $"{domainClass.Name}s", Type = $"DbSet<{domainClass.Name}>"
                });
                foreach (var method in domainClass.Methods)
                {
                    properties.Add(new Property
                    {
                        Name = $"{_nameBuilderUtil.EventName(domainClass, method)}s",
                        Type = $"DbSet<{_nameBuilderUtil.EventName(domainClass, method)}>"
                    });
                }

                foreach (var method in domainClass.CreateMethods)
                {
                    properties.Add(new Property
                    {
                        Name = $"{_nameBuilderUtil.EventName(domainClass, method)}s",
                        Type = $"DbSet<{_nameBuilderUtil.EventName(domainClass, method)}>"
                    });
                }
            }

            _propertyBuilderUtil.Build(eventStore, properties);
            var codeConstructor = _constructorBuilderUtil.BuildPublicWithBaseCall(new List <Property>(),
                                                                                  new List <Property> {
                new Property {
                    Name = "options", Type = "DbContextOptions<EventStoreContext>"
                }
            });

            eventStore.Members.Add(codeConstructor);

            nameSpace.Types.Add(eventStore);

            return(nameSpace);
        }
Beispiel #2
0
        public CodeNamespace Build(IList <DomainClass> domainClasses, IList <SynchronousDomainHook> domainHooks)
        {
            var codeTypeDeclaration = _classBuilderUtil.Build("GeneratedDependencies");

            codeTypeDeclaration.Attributes = MemberAttributes.Final | MemberAttributes.Public;

            _nameSpaceBuilderUtil.WithName("Host")
            .WithApplication()
            .WithDependencyInjection()
            .WithSqlAdapter();

            var codeMemberMethod = new CodeMemberMethod();

            codeMemberMethod.Attributes = MemberAttributes.Static | MemberAttributes.Public | MemberAttributes.Final;
            codeMemberMethod.Name       = "ConfigureGeneratedServices";
            codeTypeDeclaration.Members.Add(codeMemberMethod);
            codeMemberMethod.Parameters.Add(new CodeParameterDeclarationExpression("IServiceCollection", "collection"));

            codeMemberMethod.Statements.Add(new CodeSnippetExpression("collection.AddTransient<IEventStore, EventStore>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression("collection.AddTransient<IEventStoreRepository, EventStoreRepository>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{new QueueRepositoryInterface().Name}, {new QueueRepositoryClass().Name}>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression("collection.AddTransient<EventJobRegistration>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{new HangfireQueueInterface().Name}, HangfireQueue>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddMvc().AddApplicationPart(typeof({domainClasses[0].Name}Controller).Assembly)"));

            foreach (var domainClass in domainClasses)
            {
                _nameSpaceBuilderUtil
                .WithApplicationEntityNameSpace(domainClass.Name)
                .WithHttpAdapterEntityNameSpace(domainClass.Name)
                .WithSqlEntityNameSpace(domainClass.Name);

                codeMemberMethod.Statements.Add(new CodeSnippetExpression(
                                                    $"collection.AddTransient<I{domainClass.Name}Repository, {domainClass.Name}Repository>()"));
                codeMemberMethod.Statements.Add(new CodeSnippetExpression(
                                                    $"collection.AddTransient<{domainClass.Name}CommandHandler>()"));

                foreach (var hook in domainClass.ChildHookMethods)
                {
                    var onChildHookMethodName = _nameBuilderUtil.OnChildHookMethodName(hook);
                    codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{new DomainHookBaseClass().Name}, {onChildHookMethodName}Hook>()"));
                }
            }

            foreach (var hook in domainHooks)
            {
                _nameSpaceBuilderUtil.WithHookEntityNameSpace(hook.ClassType);
                codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{new DomainHookBaseClass().Name}, {hook.Name}Hook>()"));
            }

            var codeNamespace = _nameSpaceBuilderUtil.Build();

            codeNamespace.Types.Add(codeTypeDeclaration);

            return(codeNamespace);
        }
Beispiel #3
0
        public void AddNameSpace()
        {
            _nameSpaceBuilderUtil.WithName($"Domain.{_domainClass.Name}s").WithList();

            foreach (var childHookMethod in _domainClass.ChildHookMethods)
            {
                var className = _nameBuilderUtil.GetClassName(childHookMethod, _domainClass.Properties, _domainClass.ListProperties);
                _nameSpaceBuilderUtil.WithDomainEntityNameSpace(className);
            }

            _nameSpaceRealClass = _nameSpaceBuilderUtil.Build();
        }
Beispiel #4
0
        public CodeNamespace Build(EventStore eventStore)
        {
            var targetClass = _classBuilderUtil.Build(eventStore.Name);

            targetClass.BaseTypes.Add(new EventStoreInterface().Name);

            _nameSpaceBuilderUtil.WithName(_nameSpace).WithDomain().WithTask().WithList().WithLinq();

            _propertyBuilderUtil.BuildWithoutSet(targetClass, eventStore.Properties);
            var constructor = _constructorBuilderUtil.BuildPublic(eventStore.Properties);

            targetClass.Members.Add(constructor);

            var methodList = new List <CodeMemberMethod>();

            foreach (var eventStoreMethod in eventStore.Methods)
            {
                var method = new CodeMemberMethod();
                method.Name       = eventStoreMethod.Name;
                method.ReturnType = new CodeTypeReference(eventStoreMethod.ReturnType);
                method.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                foreach (var parameter in eventStoreMethod.Parameters)
                {
                    method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(parameter.Type),
                                                                                 parameter.Name));
                }

                methodList.Add(method);
            }

            var codeMemberMethod = methodList[0];

            codeMemberMethod.Statements.Add(new CodeSnippetExpression("var domainEventsFromHooks = new List<DomainEventBase>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression("var enumerator = domainEvents.GetEnumerator()"));

            var codeWhile = CreateLoopOverDomainEvents();

            codeMemberMethod.Statements.Add(codeWhile);
            codeMemberMethod.Statements.Add(
                new CodeSnippetExpression("await EventStoreRepository.AddEvents(domainEvents)"));
            codeMemberMethod.Statements.Add(
                new CodeSnippetExpression("await EventStoreRepository.AddEvents(domainEventsFromHooks)"));
            codeMemberMethod.Statements.Add(
                new CodeSnippetExpression($"return {new HookResultBaseClass().Name}.OkResult()"));

            targetClass.Members.Add(methodList[0]);

            var nameSpace = _nameSpaceBuilderUtil.Build();

            nameSpace.Types.Add(targetClass);
            return(nameSpace);
        }
Beispiel #5
0
        public CodeNamespace Write(IList <DomainClass> domainClasses, IList <AsyncDomainHook> domainHooks)
        {
            var codeTypeDeclaration = _classBuilderUtil.Build("GeneratedDependencies");

            codeTypeDeclaration.Attributes = MemberAttributes.Final | MemberAttributes.Public;

            _nameSpaceBuilderUtil.WithName("AsyncHost")
            .WithApplication()
            .WithDependencyInjection()
            .WithHangfire()
            .WithApplicatioBuilder()
            .WithSqlAdapter();

            var codeMemberMethod = new CodeMemberMethod();

            codeMemberMethod.Attributes = MemberAttributes.Static | MemberAttributes.Public | MemberAttributes.Final;
            codeMemberMethod.Name       = "ConfigureGeneratedServices";
            codeTypeDeclaration.Members.Add(codeMemberMethod);
            codeMemberMethod.Parameters.Add(new CodeParameterDeclarationExpression("IServiceCollection", "collection"));

            codeMemberMethod.Statements.Add(new CodeSnippetExpression("collection.AddTransient<IEventStore, EventStore>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression("collection.AddTransient<IEventStoreRepository, EventStoreRepository>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{new QueueRepositoryInterface().Name}, {new QueueRepositoryClass().Name}>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression("collection.AddTransient<EventJobRegistration>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{new HangfireQueueInterface().Name}, HangfireQueue>()"));

            foreach (var domainClass in domainClasses)
            {
                _nameSpaceBuilderUtil
                .WithApplicationEntityNameSpace(domainClass.Name)
                .WithSqlEntityNameSpace(domainClass.Name);

                codeMemberMethod.Statements.Add(new CodeSnippetExpression(
                                                    $"collection.AddTransient<I{domainClass.Name}Repository, {domainClass.Name}Repository>()"));
            }

            foreach (var hook in domainHooks)
            {
                _nameSpaceBuilderUtil.WithAsyncHookEntityNameSpace(hook.ClassType);
                codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{_nameBuilderUtil.AsyncEventHookHandlerName(hook)}>()"));
                codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{_nameBuilderUtil.AsyncEventHookName(hook)}>()"));
            }

            var codeNamespace = _nameSpaceBuilderUtil.Build();

            var codeMemberMethodApplicationConfig = new CodeMemberMethod();

            codeMemberMethodApplicationConfig.Attributes = MemberAttributes.Static | MemberAttributes.Public | MemberAttributes.Final;
            codeMemberMethodApplicationConfig.Name       = "ConfigureApplication";
            codeMemberMethodApplicationConfig.Parameters.Add(new CodeParameterDeclarationExpression("IApplicationBuilder", "app"));

            codeTypeDeclaration.Members.Add(codeMemberMethodApplicationConfig);

            codeMemberMethodApplicationConfig.Statements.Add(new CodeSnippetExpression("var option = new BackgroundJobServerOptions {WorkerCount = 1}"));
            codeMemberMethodApplicationConfig.Statements.Add(new CodeSnippetExpression("app.UseHangfireServer(option)"));
            codeMemberMethodApplicationConfig.Statements.Add(new CodeSnippetExpression("app.UseHangfireDashboard()"));

            foreach (var hook in domainHooks)
            {
                codeMemberMethodApplicationConfig.Statements.Add(new CodeSnippetExpression($"RecurringJob.AddOrUpdate<{_nameBuilderUtil.AsyncEventHookHandlerName(hook)}>(handler => handler.Run(), Cron.Minutely())"));
            }

            codeNamespace.Types.Add(codeTypeDeclaration);

            return(codeNamespace);
        }