unity-container

Prism v4: Unity or MEF?

与世无争的帅哥 提交于 2019-12-03 05:36:14
问题 I downloaded Prism v4 and ran the installer. I went into the directory and ran the two following batch files: Desktop only - Open Modularity With Mef QuickStart.bat Desktop only - Open Modularity With Unity QuickStart.bat When I compile these applications, I don't see any real difference. I've searched for MEF vs Unity and I've found some pros/cons, but nothing that specifically states whether one is "better" (and I know that is subjective) with use in Prism. I guess perhaps if I list my

WPF + MvvM + Prism

懵懂的女人 提交于 2019-12-03 03:52:34
I am new in the Wpf & Mvvm world , but I have found a couple of examples and just found that there is some different way to instantiate the model. I would like to know the best/correct way to do it. both ways are using Unity What I've foud: var navigatorView = new MainView(); navigatorView.DataContext = m_Container.Resolve<INavigatorViewModel>(); m_RegionManager.Regions["NavigatorRegion"].Add(navigatorView); What I did: var navigatorView = m_Container.Resolve<MainView>; m_RegionManager.Regions["NavigatorRegion"].Add(navigatorView); and I changed the constructor to receive viewmodel so I can

WPF with Unity Container - How to register and resolve ViewModels to Views

让人想犯罪 __ 提交于 2019-12-03 03:29:28
Hi I am trying to use Unity container in WPF MVVM application. I have not used Prism as it seems to heavy. Here is the application structure. I am trying to figure out how to resolve Views to ViewModels and dependencies of the view models (services). Application: Views MainWindow.xaml CustomerList.xaml CustomerDetail.xaml BookList.xaml BookDetail.xaml ViewModels MainViewModel CustomerListViewModel BoolListViewModel BookDetailViewModel CustomerDetailViewModel Library ICustomerService (AddCustomer, SaveCustomer, GetCustomers, GetCustomer) CustomerService:ICustomerService IBookService (GetBooks,

What are the InjectionMembers in RegisterType() calls for?

蹲街弑〆低调 提交于 2019-12-03 01:09:51
I've been working with Microsoft's Unity IOC container. There are a bunch of overloads for the RegisterType() method all looking similar to IUnityContainer RegisterType(Type t, params InjectionMember[] injectionMembers); I'm wondering when the injectionMembers parameters are for? I couldn't find any documentation for the them (even though they're in every overload) and none of the sample code I looked at use them. Am I missing something here? Are they not commonly used or did I just miss the examples? Jehof The overload with the InjectionMember array is used, when you do not provide a

Ninject vs Unity for DI [closed]

老子叫甜甜 提交于 2019-12-03 00:29:03
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . We are using ASP.net MVC. Which of these is the best DI framework Ninject or Unity and why? 回答1: Last time I looked at either of them I found Ninject slightly better. But both have their drawbacks. Ninject has a better fluent-configuration scheme. Unity seems to rely mostly

Resolve instance with multiple constructors using unity

孤者浪人 提交于 2019-12-03 00:12:17
I'd like to create an instance of a class using unity where the class has two constructors with the same number of parameters. Here is the instantiation: _unityContainer.Resolve<IGradeType>(new ParameterOverride("gradeTypeStringFromXmlFile", gradeTypeStringFromXmlFile)); And here are the constructors: public GradeType(string gradeTypeStringFromXmlFile) { _gradeTypeStringFromXmlFile = gradeTypeStringFromXmlFile; } public GradeType(Enum.GradeType gradeType) { _gradeType = gradeType; } If I try to do this I get an exception saying The type GradeType has multiple constructors of length 1. Unable

How to registerType with a PARAMETER constructor?

元气小坏坏 提交于 2019-12-02 21:08:51
How do I registertype with the container where the type doesn't have NO PARAMETER constructor. In fact my constructor accepts a string, and I normally pass in a string that represents a Path. So when I do resolve it automatically creates the new type but passing in a string? It's simple. When you register the constructor, you just pass the value you want injected for the parameter. The container matches up your constructor based on the type of value (API) or name of parameter (XML). In the API, you'd do: container.RegisterType<MyType>(new InjectionConstructor("My string here")); That will

Avoiding Service Locator Antipattern with legacy app not designed for IOC

泄露秘密 提交于 2019-12-02 20:59:28
I have read often that Service Locators in IOC are an anti-pattern . Last year we introduced IOC (Ninject specifically) to our application at work. The app is legacy, it's very big and it's fragmented. There are lots of ways a class, or a chain of classes can get created. Some are created by the web framework (which is custom), some are created by nHibernate. Lots are just scattered around in weird places. How would we handle the different scenarios and not come up with something thats not at least ServiceLocatorish and not end up with different kernels in different places (scopes like

UnityContainer.Resolve or ServiceLocator.GetInstance?

≡放荡痞女 提交于 2019-12-02 19:29:53
It could seem a stupid question because in my code everything is working, but I've registered a singleton this way with my Unity container _ambientContainer : _ambientContainer.RegisterType<Application.StateContext>(new ContainerControlledLifetimeManager()); In order to avoid to use my local field, I use: get { return ServiceLocator.Current.GetInstance<Application.StateContext>(); } inside my get property to get an instance of my object. This way I get always the same instance ( Application.StateContext is still a singleton) or does GetInstance create a new one? Is it better to use the local

Should Unity be configured in code or configuration file?

巧了我就是萌 提交于 2019-12-02 19:17:44
Microsoft's Unity dependency injection framework can be configured either through code or through the applications configuration file (app.config). Code example: IUnityContainer container = new UnityContainer() .RegisterType<IInterface, ConcreteImplementation>(); Configuration example: <unity> <containers> <container> <types> <type type="IInterface, MyAssembly" mapTo="ConcreteImplementation, MyAssembly" /> What are the advantages/disadvantages to each approach? I can think of the obvious advantage "Users can easily configure your application", and the obvious disadvantage "Users can easily