小编Tra*_*vis的帖子

如何在ASP.NET MVC 6中注册ILogger以进行注入

我有一个ASP.NET MVC 6(beta-4)应用程序.

public void ConfigureServices(IServiceCollection services)
{
    // Logging
    services.AddLogging();

    // ...
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
{
    // Add the console logger.
    loggerfactory.AddConsole(minLevel: LogLevel.Warning);

    // ...
}
Run Code Online (Sandbox Code Playgroud)

我有一个控制器......

public class HomeController : 
    Controller
{
    ILogger _logger;

    public HomeController(ILogger logger) 
    {
        _logger = logger;
    }

    // ...
}
Run Code Online (Sandbox Code Playgroud)

但是当我没有以某种方式正确地注册服务时:InvalidOperationException: Unable to resolve service for type 'Microsoft.Framework.Logging.ILogger' while attempting to activate 'HomeController'..注册记录器我做错了什么?

logging dependency-injection asp.net-core-mvc

40
推荐指数
2
解决办法
3万
查看次数

如何检测Topshelf是否在控制台模式下运行

我正在使用Topshelf与FluentSchedule结合使用Windows服务.

但是,我希望能够试运行应用程序只是启动而不执行设置计时器等的FluentSchedule代码.

有没有办法从命令行运行exe文件(即没有'install'命令)从TopShelf检查它是否在控制台模式下运行?

topshelf

12
推荐指数
2
解决办法
4105
查看次数

是否可以通过Topshelf从一个控制台应用程序启动多个服务?

正如TosShelf所说:

"You can only have ONE service! As of 3.x Topshelf the base product no longer support hosting multiple services. "

从版本3.x开始,我需要弄清楚如何集成新版本的Topshelf.

问题: 是否可以使用Topshelf从一个控制台应用程序启动多个单独的服务?我怎样才能做到这一点?

.net c# windows-services topshelf

9
推荐指数
2
解决办法
4161
查看次数

使用 MassTransit 使用交换和路由密钥发布消息

我已经关注 MassTransit 几个星期了,我对各种可能性很好奇。但是,我似乎无法完全正确地理解这些概念。

预期行为 我想将消息发布到“直接”交换与路由键绑定到两个不同的队列以执行其他活动。

当我使用 MassTransit 尝试相同的逻辑以获得更好的可扩展性时。我发现 MassTransit 根据带有扇出类型的队列名称创建自己的交换。

通过交换和路由密钥发布消息的经典代码

using (var connection = factory.CreateConnection())
        {
            using (var channel = connection.CreateModel())
            {
                channel.ExchangeDeclare(exchange, "direct");

                var body = Encoding.UTF8.GetBytes(message);

                channel.BasicPublish(exchange, routingKey, null, body);
                Console.WriteLine(" [x] Sent {0}", message);
            }
        }
Run Code Online (Sandbox Code Playgroud)

有没有办法在 MassTransit 中使用路由密钥配置直接或主题交换?

c# masstransit message-queue rabbitmq-exchange

9
推荐指数
2
解决办法
9349
查看次数

使用Topshelf安装后无法在服务下看到我的服务

我很确定答案很简单但是在这里;

我正在使用TopShelf来安装我的服务,我可以成功地从命令行安装和运行它

MyExecutable.Daemon安装MyExecutable.Daemon启动

这很好,但它必须是服务之一,并不是我尝试过;

sc create "MyExecutable.Daemon" binPath= "C:\'Program Files (x86)'\MyExecutable.Daemon.exe" DisplayName= "MyExecutable.Daemon" start= auto
Run Code Online (Sandbox Code Playgroud)

但得到了

Set-Content : A positional parameter cannot be found that accepts argument 'binpath='.
At line:1 char:1
+ sc create MyExecutable.Daemon binpath= "C:\'Program Files (x86)'\...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Set-Content], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetContentCommand
Run Code Online (Sandbox Code Playgroud)

所以我被困在这里.我在这里错过了什么?

windows powershell service install topshelf

8
推荐指数
1
解决办法
5923
查看次数

UINavigationController中的ViewController没有填充视图

我还没有找到如何使我的视图填充可用空间作为根视图控制器(或推动视图控制器)在一个UINavigationController.我试图在这里使用AutoLayout,但我怀疑这是问题.在我的应用代表中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ViewController *viewController = [[ViewController alloc] init];

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
    self.window.rootViewController = navigationController;

    [self.window makeKeyAndVisible];

    return YES;
}
Run Code Online (Sandbox Code Playgroud)

在我的 ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.translatesAutoresizingMaskIntoConstraints = NO;
    // Do any additional setup after loading the view, typically from a nib.

    UILabel *companyLabel = [[UILabel alloc] init];
    companyLabel.translatesAutoresizingMaskIntoConstraints = NO;
    companyLabel.text = @"We Build It";
    companyLabel.backgroundColor = [UIColor redColor];

    [self.view addSubview:companyLabel];

    NSDictionary *views = NSDictionaryOfVariableBindings(companyLabel);

    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[companyLabel]" options:0 …
Run Code Online (Sandbox Code Playgroud)

uinavigationcontroller ios autolayout

6
推荐指数
1
解决办法
2551
查看次数

Topshelf - 无法找到类型或命名空间名称Topshelf

我正在尝试使用Topshelf来托管控制台应用程序作为Windows服务,但我遇到了问题......

我从控制台应用程序中引用了Topshelf dll以及log4net dll.但是,当我编译时 - 无论是否带有引用Topshelf的代码,都会显示标题中提到的构建错误,然后我的Topshelf引用变为无效(以及log4net).

我觉得我错过了一些明显的东西 - 任何建议都会受到赞赏.

c# windows service topshelf

5
推荐指数
1
解决办法
1187
查看次数

Topshelf超时问题

我们正在使用Topshelf来托管服务.在启动服务之前,我们正在进行数据库调用以加载大量数据.因此,在启动服务时,我们遇到以下错误:

Start Service failed with return code '[7] ServiceRequestTimeout
Run Code Online (Sandbox Code Playgroud)

我们使用以下代码来启动服务:

HostFactory.Run(x =>
            {
                x.Service<AppService>(s =>
                {
                    s.ConstructUsing(name => new AppService(s_resolver, baseAddress, resolver));
                    s.WhenStarted(svc => svc.Start());
                    s.WhenStopped(svc => svc.Stop());
                    s.WhenShutdown(svc => svc.Shutdown());
                });

                x.EnableShutdown();
                x.RunAsLocalService();
                x.StartAutomatically();
                x.SetDisplayName("Application Host");
                x.SetDescription("Application Host");
            });
Run Code Online (Sandbox Code Playgroud)

如果我尝试使用Visual Studio启动服务,服务运行正常.但是当服务通过Topshelf托管时,我就错过了时间.

我也试过使用hostControl.RequestAdditionalTime(TimeSpan.FromSeconds(300)) 但是即使添加了额外的超时时间后,我也无法解决问题.请提供您的建议.

.net windows-services topshelf

5
推荐指数
1
解决办法
4211
查看次数

4
推荐指数
1
解决办法
3238
查看次数

在 Visual Studio Code 中创建没有语言服务器的诊断条目

我有一个相当简单的 Visual Studio Code 扩展,如果可能,我想在其中应用一些警告,而不必为其实现整个语言服务器。有没有办法直接在文档或编辑器对象上执行此操作?检查对象时我没有发现任何东西。

typescript visual-studio-code vscode-extensions

4
推荐指数
1
解决办法
495
查看次数

在Erlang中使用RabbitMQ有什么好处?

我正在学习Erlang,我来自一个很好的Python背景.我在项目中使用了RabbitMQ和Celery.

虽然Erlang具有非常强大的消息传递和并发功能,但使用RabbitMQ和Erlang有什么好处?我错过了这一点吗?为什么我不应该依赖Erlang的原生特性而不是在我的项目环境中添加另一层复杂性?

erlang rabbitmq

3
推荐指数
1
解决办法
762
查看次数

使用rabbitmq 的mastransit:为什么消息在发布时自动移动到_skipped 队列

MassTransit.3.1.2 MassTransit.Autofac.3.1.1 MassTransit.RabbitMQ.3.1.1 RabbitMQ.Client.3.6.0 Topshelf.3.3.1

一个 Topshelf Windows 服务,创建一个像这样的总线实例:

var builder = new ContainerBuilder();
builder.RegisterConsumers(Assembly.GetExecutingAssembly());
builder.Register<IBusControl>(context =>
        {
            return Bus.Factory.CreateUsingRabbitMq(rbmq =>
            {
                var host = rbmq.Host(new Uri("rabbitmq://" + BusConfig.Instance.Host + ":" + BusConfig.Instance.Port + "/" + BusConfig.Instance.VHost), h =>
                {
                    h.Username(BusConfig.Instance.UserName);
                    h.Password(BusConfig.Instance.Password);
                });
                rbmq.UseJsonSerializer();
                rbmq.UseNLog();

                rbmq.ReceiveEndpoint(BusConfig.Instance.Queue, edp =>
                {
                    edp.UseRetry(Retry.Incremental(5, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5)));
                    edp.LoadFrom(context);
                });
            });
        }).SingleInstance().As<IBusControl>().As<IBus>();

        return builder.Build().Resolve<IBusControl>();
Run Code Online (Sandbox Code Playgroud)

像这样的一个控制台应用程序?

var bus = Bus.Factory.CreateUsingRabbitMq(rbmq =>
           {
               var host = rbmq.Host(new Uri("rabbitmq://" + BusConfig.Instance.Host + ":" + BusConfig.Instance.Port + "/" + BusConfig.Instance.VHost), …
Run Code Online (Sandbox Code Playgroud)

masstransit servicebus rabbitmq

0
推荐指数
1
解决办法
3369
查看次数