ioc-container

How to tell use relevant registered MySession class by name

妖精的绣舞 提交于 2019-12-12 01:27:20
问题 I have project created from Boilerplate I have MySession class that will be used from MvcControllers and WebApi Controllers. In MySession has two derived classes: MySessionMvc: public override string UserId { get { return Thread.CurrentPrincipal.Identity.GetUserId(); } } and MySessionWebApi: public override string UserId { get { System.Web.HttpContext.Current.Request.Headers["UserId"]; } } I register both classes: IocManager.RegisterIfNot<IMySession, MySessionMvc>(DependencyLifeStyle

SetResolver in console application using Simple Injector

你说的曾经没有我的故事 提交于 2019-12-12 00:23:36
问题 I am looking to do the equivalent of this: DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container)); But in a console application. I also have cases where I need to do this in a worker role. I don't want to have to add a reference to the MVC dll all over the place. I am wondering if there is an equivalent for non-mvc projects? I need to stash the container I create so I can access it throughout my application. I thought of creating a static variable, but I'd rather not

Unable to perform dependency injection in MVC 5 Web API project using Castle Windsor

╄→尐↘猪︶ㄣ 提交于 2019-12-11 20:45:48
问题 Below is the code for controller I want to instantiate using Windsor Castle. public class TestController : ApiController { private ITestService _testService = null; public TestController(ITestService testService) { _testService = testService; } public IList<TestClass> Get() { IList<TestClass> testObjects = _testService.GetAll().ToList(); return testObjects; } } I've written following code in Global.asax.cs protected void Application_Start() { ........................ InitializeServiceLocator(

Register Multiple implementations of the same contract : one in Chilcontainer and one in the Parent

断了今生、忘了曾经 提交于 2019-12-11 20:35:53
问题 I am trying to register multiple implementations of the same interface like this :- **DLL A: Module.cs** _container.RegisterType<IFoo, Foo1>("Foo1"); **DLL B: Module.cs** var childContainer = _container.CreateChildContainer(); //childcontainer childContainer.RegisterType<IFoo, Foo2>("Foo2"); **DLL A: Resolve IFoo for Foo2** (But, resolving IFoo for Foo1 is fine) var foo2 = container.Resolve<IFoo>("Foo2"); //Error Note: The container which I receive here is the "childcontainer". Have checked

How to specify what type I need to register to specific type by Autofac

孤人 提交于 2019-12-11 20:30:59
问题 I want to specify type of weapon for different warriors public interface IWarrior { string Kill(); } public interface IWeapon { string KillSound(); } public class Zombie : IWarrior { private readonly IWeapon _weapon; public Zombie(IWeapon weapon) { _weapon = weapon; } public string Kill() { return _weapon.KillSound(); } } public class Soldier : IWarrior { private readonly IWeapon _weapon; public Soldier(IWeapon weapon) { _weapon = weapon; } public string Kill() { return _weapon.KillSound(); }

class structure for decoupling and dependency injection in windows service with an IoCcontainer

旧巷老猫 提交于 2019-12-11 19:59:12
问题 I am writing a windows service and I would like to use an IoC container for resolving dependencies in some of my classes. I have the following simple scenario. public partial class serviecclass: ServiceBase { protected override void OnStart(string[] args) { StartServer(); } public void StartServer() { //create class A // do not have an interface for ClassA as in my app there will only be //one Version of ClassA var classa=new ClassA(); classa.DoWork(); } } public ClassA { public ClassA() { }

Using an IOC Container in MVC3, are objects shared between sessions?

北城余情 提交于 2019-12-11 18:38:57
问题 I've read several articles explaining the use of static classes in a MVC webapplication. From these articles I've created a small example to prove that the static variables are really shared between user sessions. I've logged in to my site using 2 different browsers, windows authentication and 2 different user accounts. A specific variable is being set when a user has logged in, if the variable is null. After the first user has logged in the variable = 1. When I access this when user 2 starts

What is the current state of IoC containers in .NET? [closed]

三世轮回 提交于 2019-12-11 17:11:44
问题 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 8 years ago . I know similar questions have been asked before I'm looking to get the current state of IoC container framework in the .NET sphere.

IoC: Existing runtime objects rather than container-initialised prerequisites for components

China☆狼群 提交于 2019-12-11 15:54:42
问题 In my case I am using Castle Windsor as my IoC container. I would like to declare a component, where one of the constructor arguments will be set to an existing object at runtime, rather than having the IoC container create the object when it creates the component. For example, the instance of my application's main form. I suspect there are two approaches: Create the object via the container for the first time, then configure it with any necessary runtime values so that when the component

Remove coupling for EF DBContext and infrastructure layer

我的梦境 提交于 2019-12-11 12:14:57
问题 I defined my interfaces in infrastructure layer, to use Dependency Injection, but now problem, how can i resolve dependency of DBContext using interface, without adding reference to EF dll, in infrasturcure layer and service layer. 回答1: If you need to hide EF completely from your application, you will need to use the repository pattern, hide EF behind your repositories and generate (or write) POCO entities. If you're more pragmatic, you can use generic repositories with IQueryable support,