Shazter
Shazter

Reputation: 305

How two interact from two sources (view) and other Module in parallel

I have a Module for a hardware, which shall be possible to interact from View by the User and from another Module.

Question:

Shall I create a singleton instance in the MyModule_A, register this instance two my container and use this container to resolve the instance in MyModule_B?

Or

Shall I have to use a Eventaggregator two communicate between the two Modules?

The prism documentation is for me not clear in that case.

Upvotes: 0

Views: 99

Answers (1)

Haukinger
Haukinger

Reputation: 10873

Use a shared service, i.e. this:

Shall I create a singleton instance in the MyModule_A, register this instance two my container and use this container to resolve the instance in MyModule_B?

Create an interface for your driver in a third assembly (not a module) referenced by module a and module b. Then register the driver in module a, and have it injected in the view model or whatever in module b or c or even a.

Sketch:

// in the interface-assembly:

public interface IDriver
{
    bool ReadSensor();
}

// in module a:

internal class MyDriver : IDriver ...

public class MyModuleA : IModule
{
    public void Initialize()
    {
        _container.RegisterType<IDriver, MyDriver>( new ContainerControlledLifetimeManager() );
    }
}

// in module b:

internal class MyViewModel
{
    public MyViewModel( IDriver theHardware ) ...
}

Upvotes: 1

Related Questions