示例#1
0
        public static ContainerBuilder RegisterAggregate(this ContainerBuilder services, AggregateInformation a)
        {
            // Register full generic types
            services.RegisterType(a.Snapshot != null
                    ? typeof(Repository <, , , ,>).MakeGenericType(a.Aggregate, a.Snapshot, a.AggregateKey, a.EventKey, a.SnapshotKey)
                    : typeof(EventOnlyRepository <, ,>).MakeGenericType(a.Aggregate, a.AggregateKey, a.EventKey))
            .As(typeof(IRepository <, ,>).MakeGenericType(a.Aggregate, a.AggregateKey, a.EventKey))
            .InstancePerLifetimeScope();

            services.RegisterType(typeof(Session <, ,>).MakeGenericType(a.Aggregate, a.AggregateKey, a.EventKey))
            .As(typeof(ISession <, ,>).MakeGenericType(a.Aggregate, a.AggregateKey, a.EventKey))
            .InstancePerLifetimeScope();

            // Register the convenience GUID scoped ISession interface as well
            if (a.AggregateKey == typeof(Guid) && a.EventKey == typeof(Guid))
            {
                services.RegisterType(typeof(Session <>).MakeGenericType(a.Aggregate))
                .As(typeof(ISession <>).MakeGenericType(a.Aggregate))
                .InstancePerLifetimeScope();
            }

            return(services);
        }
示例#2
0
        public static ServiceCollection RegisterAggregate(this ServiceCollection services, AggregateInformation a)
        {
            // Register full generic types
            services.AddScoped(typeof(IRepository <, ,>).MakeGenericType(a.Aggregate, a.AggregateKey, a.EventKey),
                               a.Snapshot != null
                    ? typeof(Repository <, , , ,>).MakeGenericType(a.Aggregate, a.Snapshot, a.AggregateKey,
                                                                   a.EventKey, a.SnapshotKey)
                    : typeof(EventOnlyRepository <, ,>).MakeGenericType(a.Aggregate, a.AggregateKey, a.EventKey));

            services.AddScoped(typeof(ISession <, ,>).MakeGenericType(a.Aggregate, a.AggregateKey, a.EventKey),
                               typeof(Session <, ,>).MakeGenericType(a.Aggregate, a.AggregateKey, a.EventKey));

            // Register the convenience GUID scoped ISession interface as well
            if (a.AggregateKey == typeof(Guid) && a.EventKey == typeof(Guid))
            {
                services.AddScoped(typeof(ISession <>).MakeGenericType(a.Aggregate),
                                   typeof(Session <>).MakeGenericType(a.Aggregate));
            }

            return(services);
        }
示例#3
0
                new Dictionary <object, object>(); // key, value of id, aggregate

            public AggregateTypeContainer(AggregateInformation aggregateInformation, Func <object, object> byIdMethod, Func <object, Task> repositorySaveMethod)
            {
                AggregateInformation = aggregateInformation;
                GetByIdMethod        = byIdMethod;
                RepositorySaveMethod = repositorySaveMethod;
            }