I have two autofac modules WorldModule and RegionModule (separte class that inherits Module) and overwrite the load function. Both must share a worldService, service that uses an world model (singleton).
This is the worldmodule class:
builder.RegisterType<World>().AsSelf()
.AsImplementedInterfaces()
.SingleInstance();
builder.RegisterType<WorldService>().AsImplementedInterfaces();
In the region i want to have the same worldservice instance. This is the region module class:
builder.RegisterBuildCallback(c =>
{
Task.Run(async () =>
{
while (true)
{
var x = c.Resolve<IWorldService>() as WorldService;
if (x.RegionWasAssignedToRegionServers == true)
{
c.Resolve<IRegionService> ().AssignAreaMapToServer();
break;
}
await Task.Delay(200);
}
});
});