public void Subscribe_Test() { IEventBus bus = ServiceLocator.Instance.GetService <IEventBus>(); bus.UnsubscribeAll <HelloEventData>(); bus.Subscribe <HelloEventData, HelloEventHandler>(); HelloEventData data = new HelloEventData("hello world"); bus.PublishSync(data); Thread.Sleep(50); data.List.ShouldContain(data.Message); data.List.Clear(); bus.UnsubscribeAll <HelloEventData>(); Action <HelloEventData> action = m => m.List.Add(m.Message); bus.Subscribe <HelloEventData>(action); bus.PublishSync(data); Thread.Sleep(50); data.List.ShouldContain(data.Message); data.List.Clear(); bus.Unsubscribe(action); IEventHandler <HelloEventData> handler = new HelloEventHandler(); bus.Subscribe <HelloEventData>(handler); bus.PublishSync(typeof(HelloEventData), (IEventData)data); Thread.Sleep(50); data.List.ShouldContain(data.Message); data.List.Clear(); bus.Unsubscribe(handler); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(); HelloEventHandler teste = new HelloEventHandler(); }