SimpleInjectorContainerAdapter是否支持通过SimpleInjector容器注册的Sagas,使用以下代码我总是得到异常;
键入RebusPlaypen.MyMessageA,无法将RebusPlaypen调度到任何handl ERS
以下代码演示了此问题。这可能是我正在实施Saga注册错误,还是SimpleInjectorContainerAdapter不支持这种类型的注册?
digits <- function(x){as.integer(substring(x, seq(nchar(x)), seq(nchar(x))))}
generated <- function(x){ x + sum(digits(x))}
digitadition <- function(x,N) { c(x, replicate(N-1, x <<- generated(x))) }
res <- NULL
for(i in 0:50){
for(j in 2:50){
tmp <- digitadition(i,j)
IND <- 50*(i-1) + (j-1) - (i-1) #to index results
res[IND] <- tmp[length(tmp)]
}
}
df <- data.frame(number = unlist(res), generator=rep(1:50, each=49), N=2:50)
total <- table(df$number)[as.numeric(names(table(df$number)))<=50]
setdiff(1:50, as.numeric(names(total)))
sum(total)
答案 0 :(得分:1)
为完整起见,以下更改允许原始问题中的代码与Simple Injector容器一起正常工作;
public static class RebusSimpleInjectorSagaDemo
{
public static void Run()
{
var container = new Container();
container.Register<IMyDependency, MyDependency>();
// The missing registration
container.RegisterCollection(typeof(IHandleMessages<>), new [] {Assembly.GetExecutingAssembly()});**
var network = new InMemNetwork(true);
var adapter = new SimpleInjectorContainerAdapter(container);
var _bus = Configure
.With(adapter)
.Logging(l => l.ColoredConsole(Rebus.Logging.LogLevel.Error))
.Transport(t => t.UseInMemoryTransport(network,"my_nice_queue"))
.Routing(r => r.TypeBased().MapAssemblyOf<MyMessageA>("my_nice_queue"))
.Options(o =>
{
o.SetNumberOfWorkers(1);
o.SetMaxParallelism(1);
o.SimpleRetryStrategy(maxDeliveryAttempts: 1);
})
.Start();
container.Verify();
_bus.Send(new MyMessageA { CollationId = Guid.NewGuid(), FaveIceCreamFlavour = "Strawberry" }).Wait();
Console.WriteLine("Running");
Console.ReadLine();
}
}
答案 1 :(得分:0)
无论您使用哪个IoC容器,都必须确保处理程序通过它们提供的IHandleMessages<TMessage>
实现来解决。
如果您尝试
container.GetAllInstances<IHandleMessages<MyMessageA>>();
或
container.GetAllInstances<IHandleMessages<MyMessageB>>();
您将看到没有返回处理程序。这就是为什么Rebus找不到任何处理程序来发送你的消息的原因:)