static void Main(string[] args) { var container = new ContainerBuilder() .RegisterServiceBus() .RegisterHandlers(System.Reflection.Assembly.GetExecutingAssembly()) .ListenFor<SimpleMessage>() .Subscribe<SimpleMessage>(x => Console.WriteLine(string.Format("Received (delegate) '{0}' with message id of {1}", x.Title, x.Id))) .Build(); var serviceBus = container.Resolve<IServiceBus>(); Console.Write("Message: "); var message = Console.ReadLine(); while (!string.IsNullOrEmpty(message)) { serviceBus.Publish(new SimpleMessage { Title = message, Id = Guid.NewGuid() }); Console.Write("Message:"); message = Console.ReadLine(); } }
private static async void Run() { var container = new ContainerBuilder() .RegisterServiceBus() .Build(); var serviceBus = container.Resolve<IServiceBus>(); var manager = container.Resolve<IServiceBusManager>(); Console.WriteLine("Resetting demo topic..."); await manager.DeleteTopicAsync<SimpleMessage>(); Console.Write("Message: "); var message = Console.ReadLine(); Console.Write("Sending messages..."); await Send(serviceBus, message); Console.WriteLine("Done. Press any key to exit."); Console.ReadLine(); ResetEvent.Set(); }
static void Main(string[] args) { var container = new ContainerBuilder() .RegisterServiceBus() .RegisterHandlers(System.Reflection.Assembly.GetExecutingAssembly()) .Builder.Build(); var serviceBus = container.Resolve<IServiceBus>(); serviceBus.Subscribe(new Handler<SimpleMessage>(x => Console.WriteLine(string.Format("Received (delegate) '{0}' with message id of {1}", x.Title, x.Id)))); Console.WriteLine("Waiting for messages....."); var message = Console.ReadLine(); }
public void when_creating_non_registered_instance_then_can_add_registration_on_the_fly() { var container = new ContainerBuilder().Build(); var builder = new ContainerBuilder(); builder.RegisterType(typeof(Global)).AsSelf().AsImplementedInterfaces(); builder.Update(container); Assert.True(container.IsRegistered(typeof(Global))); container.Resolve<Global>(); }
public override void OnActionExecuting(HttpActionContext filterContext) { var container = new ContainerBuilder().Build(); var userServices = container.Resolve<IUserServices>(); var securityHelper = container.Resolve<ISecurityHelper>(); var token = filterContext.Request.Headers.Authorization.Parameter; var userId = securityHelper.GetUserIdForToken(token); var user = userServices.FindUserById(userId); if (user.AccessToken != token) { Trace.TraceError("[VerifyTokenAttribute] Invalid Access Token: " + token); filterContext.Response = filterContext.Request.CreateResponse( HttpStatusCode.InternalServerError, new ErrorDto { Code = int.Parse(ControllerErrorCodes.TokenMismatch), Error = ControllersErrorMessages.TokenMismatch } ); } }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); Schedulers.Initialise(); var container = new ContainerBuilder() .AddModulesFromAssembly(Assembly.GetExecutingAssembly()) .Build(); var viewModel = container.Resolve<MainWindowViewModel>(); var window = new MainWindow() { DataContext = viewModel}; window.Show(); }
public void FailedResolve() { // Issue #376: MissingManifestResourceException thrown when a ComponentNotRegisteredException is thrown. var container = new ContainerBuilder().Build(); Assert.Throws<ComponentNotRegisteredException>(() => container.Resolve<ISimpleService>()); }
public void Autofac_Throw_If_Service_Not_Registered() { var container = new ContainerBuilder().Build(); var component = container.Resolve<IServiceWithParams>(); }