ioc-container

Asp.net MVC RouteBase and IoC

一曲冷凌霜 提交于 2019-12-09 07:18:28
问题 I am creating a custom route by subclassing RouteBase. I have a dependency in there that I'd like to wire up with IoC. The method GetRouteData just takes HttpContext, but I want to add in my unit of work as well....somehow. I am using StructureMap, but info on how you would do this with any IoC framework would be helpful. 回答1: Well, here is our solution. Many little details may be omitted but overall idea is here. This answer may be a kind of offtop to original question but it describes the

Castle project per session lifestyle with ASP.NET MVC

淺唱寂寞╮ 提交于 2019-12-09 06:07:47
问题 I'm really new to Castle Windsor IoC container. I wanted to know if theres a way to store session variables using the IoC container. I was thinking something in the line of this: I want to have a class to store search options: public interface ISearchOptions{ public string Filter{get;set;} public string SortOrder{get;set;} } public class SearchOptions{ public string Filter{get;set;} public string SortOrder{get;set;} } And then inject that into the class that has to use it: public class

IoC Dependency Injection for stateful objects (not global)

孤人 提交于 2019-12-09 06:07:20
问题 I'm new to this IoC and DI business- I feel like I get the concept if you are passing along objects that are of a global scope, but I don't get how it works when you need to pass around an object that is of a specific logical state. So, for instance, if I wanted to inject a person object into a write file command object- how would I be able to choose the correct person object dynamically? From what I have seen, I could default construct the object, but my disconnect is that you wouldn't use a

Does Simple Injector have a way to RegisterConditional with object factory?

℡╲_俬逩灬. 提交于 2019-12-09 05:37:28
问题 I see Simple Injector's Container has this method public void RegisterConditional<TService, TImplementation>( Predicate<PredicateContext> predicate ) But I want to use the different object of the same implementation for different service, so what overloaded method I need would look like this public void RegisterConditional<TService>( Func<TService> instanceCreator, Predicate<PredicateContext> predicate ) But the SimpleInjector doesn't have it. I am trying to find the other Container's methods

What is the use of an IoC framework in an MVC application? [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 05:23:01
问题 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 6 years ago . I'm trying to understand the use of an IoC framework like StructureMap, but i can't help thinking that these "design patterns" are

Is it correct to have many Castle Windsor containers per application if those containers belong to different tiers?

故事扮演 提交于 2019-12-09 03:51:33
问题 I've been playing around with Castle Windsor lately and realized I could use it to back a container-like object I currently use already. So far I've only read information about an application having only one container instance per application. Is it correct to have many containers per application if those containers belong to different tiers? The reason I ask is because I'd like to take advantage of Windsor's dependency resolution and XML configuration for my own container-like object. I

Antipatterns of IoC container usage. Why IoC containers are so complex and used so “fancy” way?

戏子无情 提交于 2019-12-08 22:17:32
问题 I'm seriously start thinking that usage of IoC container provokes to create overdesigned solutions (at least it provokes me to try to use various unnecessary features:). It's the time to synchronize my "IoC" antipatterns list with community one's.. My short experience tell that it is absolutely enough to call Resolve method once per application at startup to resolve some infrastructure singletons and initiate with them "transient object's factory" that could produce new "smaller life time

Unity (dependency injection): How to pass in a parameter to the constructor in RegisterType

别来无恙 提交于 2019-12-08 19:49:23
问题 Can anyone help? I have a wpf app (shouldn't matter) and in the Onstart i have my bootstrap stuff.. Its like this.. // Create unity container my service and repository container = new UnityContainer() .RegisterType<ISecurityRepository, SecurityRepository>() .RegisterType<ISecurityService, SecurityService>(); Basically ISecurityService expects me to pass in a ISecurityRepository, hence the above fails. But i am little confused, do i have to create a new IsecurityRespository and then pass it in

Dependency Injection and .NET Attributes

微笑、不失礼 提交于 2019-12-08 18:33:24
I have a couple of method attributes which do some logging. Our logging code sits behind an interface (ILog) and I'd like it if the attributes were only dependent upon that interface as opposed to an implementation. This isn't really about testability or dependency inversion so much as it is about keeping the coupling of components clean. An example would be where we have a web (Mvc) specific attribute as follows: HandleExceptionAttribute : FilterAttribute, IExceptionFilter { public void OnException(ExceptionContext context) { LogFactory.CreateInstance().Info("message here", "log entry type");

Unity to dispose of object

微笑、不失礼 提交于 2019-12-08 18:14:02
问题 Is there a way to make Unity dispose property-injected objects as part of the Teardown? The background is that I am working on an application that uses ASP.NET MVC 2, Unity and WCF. We have written our own MVC controller factory that uses unity to instantiate the controller and WCF proxies are injected using the [Dependency] attribute on public properties of the controller. At the end of the page life cycle the ReleaseController method of the controller factory is called and we call