/// <summary>
        /// 打印组件信息
        /// </summary>
        public static string PrintComponent <T>(this Autofac.ILifetimeScope container)
        {
            IComponentRegistry            component     = container.ComponentRegistry;                                      //注册处
            List <IComponentRegistration> registrations = component.RegistrationsFor(new TypedService(typeof(T))).ToList(); //注册信息表

            return(GetComponent(registrations));
        }
        /// <summary>
        /// Retrieve registrations for an unregistered service, to be used
        /// by the container.
        /// </summary>
        /// <param name="service">The service that was requested.</param>
        /// <param name="registrationAccessor">A function that will return existing registrations for a service.</param>
        /// <returns>Registrations providing the service.</returns>
        public IEnumerable <IComponentRegistration> RegistrationsFor(Service service, Func <Service, IEnumerable <IComponentRegistration> > registrationAccessor)
        {
            var seenRegistrations = new HashSet <IComponentRegistration>();
            var seenServices      = new HashSet <Service>();
            var lastRunServices   = new List <Service> {
                service
            };

            while (lastRunServices.Any())
            {
                var nextService = lastRunServices.First();
                lastRunServices.Remove(nextService);
                seenServices.Add(nextService);
                foreach (var registration in _registry.RegistrationsFor(nextService).Where(r => !r.IsAdapting()))
                {
                    if (seenRegistrations.Contains(registration))
                    {
                        continue;
                    }

                    seenRegistrations.Add(registration);
                    lastRunServices.AddRange(registration.Services.Where(s => !seenServices.Contains(s)));

                    var r = registration;
                    yield return(RegistrationBuilder.ForDelegate(r.Activator.LimitType, (c, p) => c.ResolveComponent(r, p))
                                 .Targeting(r)
                                 .As(r.Services.ToArray())
                                 .ExternallyOwned()
                                 .CreateRegistration());
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Retrieve registrations for an unregistered service, to be used
 /// by the container.
 /// </summary>
 /// <param name="service">The service that was requested.</param>
 /// <param name="registrationAccessor">A function that will return existing registrations for a service.</param>
 /// <returns>Registrations providing the service.</returns>
 public IEnumerable <IComponentRegistration> RegistrationsFor(Service service, Func <Service, IEnumerable <IComponentRegistration> > registrationAccessor)
 {
     // Issue #475: This method was refactored significantly to handle
     // registrations made on the fly in parent lifetime scopes to correctly
     // pass to child lifetime scopes.
     return(_registry.RegistrationsFor(service)
            .Where(r => !r.IsAdapting())
            .Select(r => RegistrationBuilder.ForDelegate(r.Activator.LimitType, (c, p) => c.ResolveComponent(r, p))
                    .Targeting(r)
                    .As(service)
                    .ExternallyOwned()
                    .CreateRegistration()));
 }
        protected virtual void OnContainerConfigured(IComponentRegistry registry)
        {
            var service = new TypedService(typeof(ITransportMessages));

            registry.RegistrationsFor(service).First().Activated += (s, e) =>
            {
                var subscriber = e.Context.Resolve <ISubscribeToMessages>();
                foreach (var request in this.requests)
                {
                    subscriber.Subscribe(request.Key, null, request.Value.ToArray());
                }
            };
        }
        /// <summary>
        /// Retrieve registrations for an unregistered service, to be used
        /// by the container.
        /// </summary>
        /// <param name="service">The service that was requested.</param>
        /// <param name="registrationAccessor">A function that will return existing registrations for a service.</param>
        /// <returns>Registrations providing the service.</returns>
        public IEnumerable <IComponentRegistration> RegistrationsFor(Service service, Func <Service, IEnumerable <IComponentRegistration> > registrationAccessor)
        {
#if !WINDOWS_PHONE
            var seenRegistrations = new HashSet <IComponentRegistration>();
            var seenServices      = new HashSet <Service>();
#else
            var seenRegistrations = new List <IComponentRegistration>();
            var seenServices      = new List <Service>();
#endif
            var lastRunServices = new LinkedList <Service>();
            lastRunServices.AddFirst(service);

            while (lastRunServices.Count > 0)
            {
                var nextService = lastRunServices.First.Value;
                lastRunServices.RemoveFirst();
                seenServices.Add(nextService);
                foreach (var registration in _registry.RegistrationsFor(nextService))
                {
                    if (registration.IsAdapting() || seenRegistrations.Contains(registration))
                    {
                        continue;
                    }

                    seenRegistrations.Add(registration);
                    foreach (var serv in registration.Services)
                    {
                        if (!seenServices.Contains(serv))
                        {
                            lastRunServices.AddLast(serv);
                        }
                    }

                    var r = registration;
                    yield return(RegistrationBuilder.ForDelegate((c, p) => c.ResolveComponent(service, r, p))
                                 .Targeting(r)
                                 .As(r.Services.ToArray())
                                 .ExternallyOwned()
                                 .CreateRegistration());
                }
            }
        }
Beispiel #6
0
        public IEnumerable <IComponentRegistration> RegistrationsFor(Service service, Func <Service, IEnumerable <IComponentRegistration> > registrationAccessor)
        {
            // Issue #475: This method was refactored significantly to handle
            // registrations made on the fly in parent lifetime scopes to correctly
            // pass to child lifetime scopes.
            foreach (var registration in _registry.RegistrationsFor(service).Where(r => !r.IsAdapting()))
            {
                var r = registration;
                yield return(RegistrationBuilder.ForDelegate(r.Activator.LimitType, (c, p) => c.ResolveComponent(r, p))
                             .Targeting(r)
                             .As(service)
                             .ExternallyOwned()
                             .CreateRegistration());
            }

            //return new <RegistrationsFor>d__a(-2) {
            //    <>4__this = this,
            //    <>3__service = service,
            //    <>3__registrationAccessor = registrationAccessor
            //};
        }
Beispiel #7
0
 public IEnumerable <IComponentRegistration> RegistrationsFor(Service service)
 {
     return(_registry.RegistrationsFor(service));
 }
 protected virtual void OnContainerConfigured(IComponentRegistry registry)
 {
     var service = new TypedService(typeof(ITransportMessages));
     registry.RegistrationsFor(service).First().Activated += (s, e) =>
     {
         var subscriber = e.Context.Resolve<ISubscribeToMessages>();
         foreach (var request in this.requests)
             subscriber.Subscribe(request.Key, DateTime.MaxValue, request.Value.ToArray());
     };
 }