Example #1
0
        public ValueTask StartCollectors(CancellationToken token = default)
        {
            var genericContianerType  = typeof(CollectorIntervalContainer <>);
            var genericContianerIType = typeof(CollectorIntervalContainer <>);

            // Filter all instance which can resolve as ICollector
            CollectorReadScope = CurrentScope.BeginLifetimeScope((builder) =>
            {
                foreach (var type in RegisteredCollector)
                {
                    var instance = CurrentScope.Resolve(type);
                    if (instance is ICollector collector)
                    {
                        var containerType  = genericContianerType.MakeGenericType(type);
                        var containerIType = genericContianerIType.MakeGenericType(type);
                        builder.RegisterType(containerType).As(containerIType);
                    }
                }
            });

            foreach (var type in RegisteredCollector)
            {
                var containerIType = genericContianerIType.MakeGenericType(type);
                var container      = CollectorReadScope.Resolve(containerIType) as ICollectorContainer;
                container.Run(token);
            }
            return(default);