当前位置: 首页>>代码示例>>C#>>正文


C# ContainerBuilder.Resolve方法代码示例

本文整理汇总了C#中Autofac.ContainerBuilder.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.Resolve方法的具体用法?C# ContainerBuilder.Resolve怎么用?C# ContainerBuilder.Resolve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Autofac.ContainerBuilder的用法示例。


在下文中一共展示了ContainerBuilder.Resolve方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        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();
            }
        }
开发者ID:mahizsas,项目名称:Simple.ServiceBus,代码行数:26,代码来源:Program.cs

示例2: Run

        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();
        }
开发者ID:perokvist,项目名称:Simple.ServiceBus,代码行数:19,代码来源:Program.cs

示例3: when_creating_non_registered_instance_then_can_add_registration_on_the_fly

        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>();
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:12,代码来源:AutofacFixture.cs

示例4: OnActionExecuting

        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
                    }
                    );
            }
        }
开发者ID:MakingSense,项目名称:webapi-seed,代码行数:22,代码来源:VerifyTokenAttribute.cs

示例5: OnStartup

        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();
        }
开发者ID:samueldjack,项目名称:CrunchAPIExplorer,代码行数:15,代码来源:App.xaml.cs

示例6: FailedResolve

 public void FailedResolve()
 {
     // Issue #376: MissingManifestResourceException thrown when a ComponentNotRegisteredException is thrown.
     var container = new ContainerBuilder().Build();
     Assert.Throws<ComponentNotRegisteredException>(() => container.Resolve<ISimpleService>());
 }
开发者ID:arronchen,项目名称:Autofac,代码行数:6,代码来源:ResolveFixture.cs

示例7: Autofac_Throw_If_Service_Not_Registered

 public void Autofac_Throw_If_Service_Not_Registered()
 {
     var container = new ContainerBuilder().Build();
     var component = container.Resolve<IServiceWithParams>();
 }
开发者ID:ChrisFulstow,项目名称:Idiocy,代码行数:5,代码来源:AutofacTests.cs


注:本文中的Autofac.ContainerBuilder.Resolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。