本文整理汇总了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();
}
}
示例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();
}
示例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>();
}
示例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
}
);
}
}
示例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();
}
示例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>());
}
示例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>();
}