【发布时间】:2016-06-23 16:10:08
【问题描述】:
有没有办法让 WebJob 项目中的默认 Functions 类成为 internal?我们正在使用作业激活器通过 Unity 注入一些 internal 的依赖项,这要求 Functions 类也必须是 internal。运行 Web 作业时,我们看到以下错误:
No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
当我们创建所有依赖项public 时,它工作正常,所以我知道我的触发器或作业主机配置没有任何问题。
这是我的程序类:
class Program
{
static void Main()
{
var config = new JobHostConfiguration
{
JobActivator = new Activator(new UnityContainer())
};
config.UseServiceBus();
var host = new JobHost(config);
host.RunAndBlock();
}
}
这是我的 Functions 类的简化版本:
internal class Functions
{
private readonly IMyInternalDependency _dependency;
public Functions(IMyInternalDependency dependency)
{
_dependency = dependency;
}
public function DoSomething([ServiceBusTrigger("my-queue")] BrokeredMessage message)
{
// Do something with the message
}
}
【问题讨论】:
-
我对 WebJobs 了解不多,但是您可以让私有或内部类实现公共接口,并将该对象作为其接口传递。
-
你能发布一些代码,或者代码示例以获得一些上下文吗?
标签: c# azure unity-container azure-webjobs