2

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);
                }
            });
        });
Dan Cehan
  • 41
  • 5
  • Looks OK, resolving c should work. – Shahar Shokrani Mar 26 '19 at 14:51
  • Could you explain more what you are trying to do ? how `RegionWasAssignedToRegionServers` changes ? what is `AssignAreaMapToServer`? Why do you need a single instance ? – Cyril Durand Mar 27 '19 at 14:48
  • well, I solved in another way. The main purpose of this is to await until all region servers will be connected with the world server. After that the world-service will compute which region-map will be associate with which region-server. Here in this instance I will set the RegionWasAssignedToRegionServers flag true. This is why I needed a common world-service instance at the time. – Dan Cehan Mar 29 '19 at 07:06

0 Answers0