public IHttpController Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
        {
            HttpContext     httpContext = HttpContext.Current;
            IWork           work        = httpContext.GetWork();
            IHttpController controller  = work.CreateComponent(controllerType) as IHttpController;

            work.PublishEvent(new ControllerCreatedEvent(this,
                                                         request,
                                                         controllerDescriptor,
                                                         controller));
            return(controller);
        }
Ejemplo n.º 2
0
        public void ChangeInstance()
        {
            var app = AppSetup.Start <TestAppModule>();
            IComponentContainer container = app.GetAppContainer <IComponentContainer>();

            container.ComponentCreating += (sender, e) =>
            {
                if (e.CreatedObject is IIdService)
                {
                    e.Replace(new EmptyIdService());
                }
            };
            using (IWork work = app.BeginWork("Test"))
            {
                IIdService service = work.CreateComponent <IIdService>();
                Assert.IsInstanceOfType(service, typeof(EmptyIdService));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 发布一个事件
        /// </summary>
        /// <param name="work"></param>
        /// <param name="event"></param>
        public static void PublishEvent(this IWork work, Event @event)
        {
            IEventBus eventBus = work.CreateComponent <IEventBus>();

            eventBus.Publish(@event);
        }