Important issue to solve (Unity)

Dec 22, 2009 at 11:45 AM
Edited Dec 22, 2009 at 12:01 PM

Hello,

I was following your tutorials on codeplex and this gave me a really good overview into the cinch framework. After looking into the sourcecode hosted here I have although one issues that prevent me from using this quite fabolous framework:

  1. Hard wired dependency to unity
  2. Lack of interfaces

Let me explain my issues:

Hard wired dependency to unity:

By using the static singleton in ViewModelBase which has hardwired dependencies to unity you are forcing the client of your framework to use unity. It would be much better to let the client decide which kind of IoC/DI framework to use. And actually you are violating the SRP (single responsibility pattern) by including the Resolve method into the ViewModelBase. I suggest you extract the service retrieval into a factory with an appropriate interface. Then you could provide a standard factory which retrieves your standard types. Clients are then free to create a new factory implementing your interface and use their own IoC/DI framework for service and type retrieval.

Lack of interfaces:

For example the mediator. It would be so easy to extract an interface IMediator which would allow the client to inject IMediator by using IoC/DI into the class. If not the client needs to do the following for each type which is not "interfaced" for better testability:

 

public interface IMediatorProvider {

void Register(object target);
// etc.

}

public class MediatorProvider  : IMediatorProvider {

public MediatorProvider(Mediator mediator) {
this.Mediator = mediator;

}

protected Mediator Mediator { get; private set; }

public void Register(object target) { Mediator.Register(target); } } public class SomeClassUsingMediator { public SomeClassUsingMediator(IMediatorProvider mediator) { mediator.Register(this); } }

 

Daniel

Coordinator
May 2, 2010 at 7:13 AM

Thanks you are correct, I will look into this.

Coordinator
May 4, 2010 at 8:19 AM
Daniel I have added is so a default Unity provider is supplied internally in Cinch, but users can swap this out by injecting a new IIOCProvider implementation into ViewModel constructor. If none is injected to constructor Cinch will use Unity as default.
May 4, 2010 at 12:46 PM
Edited May 4, 2010 at 12:47 PM

Hy

I see but your work is only half finished! See:

               ViewModelBase.isInitialised = false;

                //ILogger : Allows MessageBoxs to be shown 
                logger = (ILogger)this.iocProvider.GetTypeFromContainer<ILogger>();

                ServiceProvider.Add(typeof(ILogger), logger);

                //IMessageBoxService : Allows MessageBoxs to be shown 
                IMessageBoxService messageBoxService = 
                    (IMessageBoxService)UnitySingleton.Instance.Container.Resolve(
                        typeof(IMessageBoxService));

                ServiceProvider.Add(typeof(IMessageBoxService), messageBoxService);

                //IOpenFileService : Allows Opening of files 
                IOpenFileService openFileService = 
                    (IOpenFileService)UnitySingleton.Instance.Container.Resolve(
                        typeof(IOpenFileService));
                ServiceProvider.Add(typeof(IOpenFileService), openFileService);

                //ISaveFileService : Allows Saving of files 
                ISaveFileService saveFileService =
                    (ISaveFileService)UnitySingleton.Instance.Container.Resolve(
                        typeof(ISaveFileService));
                ServiceProvider.Add(typeof(ISaveFileService), saveFileService);

                //IUIVisualizerService : Allows popup management
                IUIVisualizerService uiVisualizerService =
                    (IUIVisualizerService)UnitySingleton.Instance.Container.Resolve(
                        typeof(IUIVisualizerService));
                ServiceProvider.Add(typeof(IUIVisualizerService), uiVisualizerService);


Daniel

Coordinator
May 7, 2010 at 4:28 PM

Ah crap, missed that, Ill fix that.

Coordinator
May 8, 2010 at 8:22 AM

Daniel I have fixed all that now, had major SVN issues, is all good now though