inversion-of-control

Resolving windows in Structure Map or how to manage multiple windows in WPF MVVM?

雨燕双飞 提交于 2019-12-17 23:39:39
问题 I have been reading Mark Seeman's book on dependency injection in .NET and I'm struggling to configure composition root in WPF application. My container will be registered in the application startup method: protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); var container = new Container(); container.Configure(r => { r.For<IAccountServices>().Use<AccountServicesProxy>(); r.For<MainWindow>().Use<MainWindow>(); }); } This makes sense as the application startup represents

ASP.NET MVC & Windsor.Castle: working with HttpContext-dependent services

十年热恋 提交于 2019-12-17 23:25:58
问题 I have several dependency injection services which are dependent on stuff like HTTP context. Right now I'm configuring them as singletons the Windsor container in the Application_Start handler, which is obviously a problem for such services. What is the best way to handle this? I'm considering making them transient and then releasing them after each HTTP request. But what is the best way/place to inject the HTTP context into them? Controller factory or somewhere else? 回答1: With Castle Windsor

How to register a Controller into ASP.NET MVC when the controller class is in a different assembly?

天涯浪子 提交于 2019-12-17 23:03:30
问题 My goal is to modify asp.net mvc's controller registery so that I can create controllers and views in a separate (child) assembly, and just copy the View files and the DLLs to the host MVC application and the new controllers are effectively "Plugged In" to the host app. Obviously, I will need some sort of IoC pattern, but I'm at a loss. My thought was to have a child assembly with system.web.mvc referenced and then to just start building controller classes that inherited from Controller :

DIP vs. DI vs. IoC [closed]

强颜欢笑 提交于 2019-12-17 22:34:32
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . For about 2 months I've been reading everything I can find for these 3 topics and I'm not yet sure I got it. Dependency Inversion

IoC in class library. Where to bootstrap

試著忘記壹切 提交于 2019-12-17 21:53:19
问题 I'm using a class library that can be reused by other components. In this class library I'm using unity for dependency injection. For this class library I create a test project. The caller also gets a test project. One thing I'm uncertain about is the location of the bindings. Should I incorporate this in the class library or should I do this from the calling application? 回答1: This is an interesting problem. How can you dependency inject re-usable assemblies that do not have an entry point. I

'Autofac Circular Component Dependency Detected' Error

北慕城南 提交于 2019-12-17 20:24:08
问题 I am new to IoC and am using Autofac in my current project. I have the following 2 classes: public class UserService : IUserService { private readonly IUserRepository _repo; private readonly IMailService _mailService; public UserService(IUserRepository repo, IMailService mailService) { _repo = repo; _mailService = mailService; } } public class MailService : IMailService { private readonly IMailRepository _repo; private readonly IUserService _userService; public MailService(IMailRepository

What are the best practices for class libraries using dependency injection for internal operations? [duplicate]

戏子无情 提交于 2019-12-17 20:10:03
问题 This question already has answers here : Dependency Inject (DI) “friendly” library (4 answers) Closed 3 years ago . What should I be careful about when building a class library complex enough to use internal dependency injection? Assuming that it will use Castle Windsor (as an example), what would be the best place/method to configure the container, given that the library will be used by simple console application (with no DI), web forms using the same container (Castle Windsor), and web apps

Is MEF a replacement for System.Addin? [duplicate]

会有一股神秘感。 提交于 2019-12-17 19:48:29
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Choosing between MEF and MAF (System.AddIn) Is the Managed Extensibility Framework a replacement for System.Addin? Or are they complementary? 回答1: It is touched in the MSDN Forums here: Comparison to the AddIn libraries? And also by Krzysztof Cwalina in his blog on the release of MEF: Managed Extensibility Framework Summary : they live side by side. 回答2: Short answer no it is not. System.Addin allows you to

How to define a default constructor by code using StructureMap?

 ̄綄美尐妖づ 提交于 2019-12-17 19:33:26
问题 I can't figure out how to define the default constructor (when it exists overloads) for a type in StructureMap (version 2.5) by code. I want to get an instance of a service and the container has to inject a Linq2Sql data context instance into it. I wrote this in my 'bootstrapper' method : ForRequestedType<MyDataContext>().TheDefault.Is.OfConcreteType<MyDataContext>(); When I run my app, I got this error : StructureMap Exception Code: 202 No Default Instance defined for PluginFamily

Unity: Implicit ResolvedParameter for unnamed registrations

有些话、适合烂在心里 提交于 2019-12-17 18:30:13
问题 The UserService constructor has two parameters, a IUnitOfWork and a IUserRepository : public UserService(IUnitOfWork unitofWork, IUserRepository userRepository) { ... } I am using named registrations to differentiate between multiple instances of IUnitOfWork , so when registering the UserService with the Unity container, I need to explicitly specify the parameters using an InjectionConstructor : container.RegisterType<IUserService, UserService>( new InjectionConstructor( new ResolvedParameter