ioc-container

Creating new instances while still using Dependency Injection

ぃ、小莉子 提交于 2019-12-05 08:30:58
A quick description of the environment: I have a class that represents a chatroom and has a dependency on a logger. It's not the same as a system-wide logger with cross-cutting concerns, but a logger that's tied to that specific chatroom. It logs all activity in that chatroom to it's unique log file. When the chatroom is created I want to open the log file, and when it's destroyed I want to close the log file. The Problem Here's the relevant code I'm using. public interface IChatroomLogger { void Log(ServerPacket packet); void Open(); void Close(); } public class ChatroomLogger :

IoC Castle Windsor - No parameterless constructor defined for this object

六眼飞鱼酱① 提交于 2019-12-05 07:51:27
I'm getting the 'No parameterless constructor defined for this object' on my controller when the controller and its dependencies are being registered accordingly via (DI/IoC) pattern using Castle Windsor. Can someone take a look at the following and see my error because i can't see it. Code for registration on global.asax public class MyApplication : System.Web.HttpApplication { public MvcApplication() { this.container = new WindsorContainer().Install(new DependencyInstaller()); } protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register

How to do a registration in Simple Injector after a GetInstance call / Alternate solution?

帅比萌擦擦* 提交于 2019-12-05 07:26:20
Consider the following example: public class CommunicationClient : IClient { public CommunicationClient(IServerSettings settings) { ... } // Code } public class SettingsManager : ISettingsManager { SettingsManager(IDbSettingManager manager) // Code public IDictionary<string, string> GetSettings() { ... } } Problem : While performing registrations (using SimpleInjector ), I need to provide values that are obtained from an instance of SetingsManager and fill ServerSettings instance (concrete type for IServerSettings ) but if I call GetInstance<ISettingsManager> before registering

How to create Illuminate/Support/Facade/App facade for standalone Illuminate IoC Container

こ雲淡風輕ζ 提交于 2019-12-05 06:43:31
In my standalone (without Laravel) project i want to use Illuminate IoC container. Also i would like to access the app container through App facade provided by illuminate/support component. I installed both components (v5.0.28). Here is my (simplified) code: function setup_App(){ $container = new Illuminate\Container\Container(); Illuminate\Support\Facades\Facade::setFacadeApplication($container); class_alias('Illuminate\Support\Facades\App', 'App'); } setup_App(); App::bind('w', 'Widget'); $widget = App::make('w'); Unfortunately, trying to bind something results in: Fatal error: Call to

Can Castle.Windsor do automatic resolution of concrete types

拈花ヽ惹草 提交于 2019-12-05 06:13:51
We are evaluating IoC containers for C# projects, and both Unity and Castle.Windsor are standing out. One thing that I like about Unity (NInject and StructureMap also do this) is that types where it is obvious how to construct them do not have to be registered with the IoC Container. Is there way to do this in Castle.Windsor? Am I being fair to Castle.Windsor to say that it does not do this? Is there a design reason to deliberately not do this, or is it an oversight, or just not seen as important or useful? I am aware of container.Register(AllTypes... in Windsor but that's not quite the same

Should I encapsulate my IoC container?

耗尽温柔 提交于 2019-12-05 05:49:16
Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted. I'm trying to decide whether or not it makes sense to go through the extra effort to encapsulate my IoC container. Experience tells me that I should put a layer of encapsulation between my apps and any third-party component. I just don't know if this is bordering on overkill. I can think of situations where I might want to switch containers. For instance, my current container ceases to be maintained,

How to reuse a transient dependency in same context with Castle Windsor DI container

浪子不回头ぞ 提交于 2019-12-05 05:08:46
问题 If I have the following setup, how can I configure my container to use the same database, when objects are created in the same context public class Database { } public interface IRepository { Database Database { get; } } public interface IFooRepository : IRepository { } public interface IBarRepository : IRepository { } public class FooRepository : IFooRepository { public Database Database { get; private set; } public FooRepository(Database database) { this.Database = database; } } public

Does Resolve<T>() return objects per-session?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 03:44:05
问题 In Microsoft Unity IoC, if I call Resolve<SomeType>() , can I guarantee that the object returned is the one that was created during the current session? For example, three users sign on, and let's say that the object of SomeType that gets created in the container has different values for each user. Will a call to Resolve return the object that was created for the current user? Or would it do something stupid like return the last one that was created? I'm having troubles testing this myself

Simple Injector pass hard coded values into constructor

六月ゝ 毕业季﹏ 提交于 2019-12-05 02:16:16
In Simple Injector I can do the following: container.RegisterSingle<IAuctionContext>(() => new AuctionContext( new Uri("http://localhost:60001/AuctionDataService.svc/"))); What I am doing here is saying that when IAuctionContext is found, replace it with this new AuctionContext . The problem is that with the call to RegisterSingle , only a single instance of AuctionContext will be used. What I'd like it to be able to pass in a Uri parameter as above but not have the single instance but allow a new instance each time. How is this possible? The value you are trying to inject is a simple hard

Access Request in Service Provider After Applying Middleware

让人想犯罪 __ 提交于 2019-12-05 01:47:11
问题 Bindings I'm using bindings in my service provider between interface and implementation: public function register() { $this->app->bind('MyInterface', MyImplementation::class); } Middleware In my middleware, I add an attribute to the request: public function handle($request, Closure $next) { $request->attributes->add(['foo' => 'bar]); return $next($request); } Now, I want to access foo in my service provider public function register() { $this->app->bind('MyInterface', new MyImplementation(