Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Just a quick recapitualtion:
- We have
- public interface IModalDialog
- - implemented by two Windows-derived classes: SimpleDialogWindow, SimpleDialogWindow2
- public interface IModalDialogService
- - implemented by: public class ModalDialogService : IModalDialogService
- Variant 1.
- <code>
- IUnityContainer container = new UnityContainer();
- container.RegisterType<IModalDialogService, ModalDialogService>(new ContainerControlledLifetimeManager());
- container.RegisterType<Func<string, IModalDialog>>
- (
- new InjectionFactory(
- c => new Func<string, IModalDialog>(name =>
- {
- switch (name)
- {
- case "SimpleDialogWindow2":
- return new SimpleDialogWindow2();
- case "SimpleDialogWindow":
- default:
- return new SimpleDialogWindow();
- }
- })
- )
- );
- </code>
- Variant 2.
- <code>
- IUnityContainer container = new UnityContainer();
- container.RegisterType<IModalDialogService, ModalDialogService>(new ContainerControlledLifetimeManager());
- container.RegisterType<IModalDialog, SimpleDialogWindow>("SimpleDialogWindow");
- container.RegisterType<IModalDialog, SimpleDialogWindow2>("SimpleDialogWindow2");
- container.RegisterType<Func<string, IModalDialog>>
- (
- new InjectionFactory(
- c => new Func<string, IModalDialog>(name => {
- return container.Resolve<IModalDialog>(name);
- }
- )
- ));
- </code>
- The first variant is nice because there are no dependencies.
- The second variant is nice because if IModalDialog implementation had further dependencies, Unity would resolve it for us.
- Question: Could there be any problem with the fact that we are using a Unity reference inside the factory that is used inside the ViewModel?
- Question2: I know that using the local variable 'container' inside lambda function for reference is bad. Would storing the reference inside some static class member be better that using new operator
- to create the container?
- Main Question: I am no sure I am doing the auto-factory type correctly with Variant1/2? Is there a better/another way to have Unity implement the auto-factory in this particular case?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement