ioc-container

How to registerType with a PARAMETER constructor?

落花浮王杯 提交于 2019-12-04 08:03:17
问题 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? 回答1: 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

Laravel ioc automatic resolution - works from controller but not from custom class

半城伤御伤魂 提交于 2019-12-04 08:02:50
Namespaces omitted for brevity... I have written the following service provider and registered in config/app.php: class OfferServiceProvider extends ServiceProvider { public function register() { $this->registerLossControlManager(); } protected function registerLossControlManager() { $this->app->bind('LossControlInterface', 'LossControl'); } } Here is my LossControlInterface interface LossControlInterface { /** * @param int $demandId * @param float $offerTotal * @param float $productTotal * @param null|int $partnerId * @return mixed */ public function make($demandId, $offerTotal, $productTotal

Access or get Autofac Container inside a static class

雨燕双飞 提交于 2019-12-04 07:13:24
I need to get or access to my IoC container in a static class. This is my (simplified) scenario: I register dependencies for ASP .net Web Api in a Startup class (but also I do this for MVC or WCF. I have a DependecyResolver project, but for simplicity, consider the following code) // Web Api project - Startup.cs public void Configuration(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); var builder = new ContainerBuilder(); // ... Omited for clarity builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies()) .AsClosedTypesOf(typeof(IHandle<>))

how to use xUnit and FsCheck with IoC and mocking in F#

∥☆過路亽.° 提交于 2019-12-04 06:40:46
问题 I want to write unit tests F# using property base testing technic. however I came across several obstacle. Code I want to test is in C# Domain objects come from EF i.e. no constructors only mutable properties sut is a class that will require a lot of constructor injections. Their number will change quite frequently as we add new functions. We do not want to change old tests when we add new parameter to constructor. sut already exists and is working so changing it pattern to take only one

Autofac with Open Generics and Type Specified at Runtime

回眸只為那壹抹淺笑 提交于 2019-12-04 06:06:26
The documentation states that Autofac supports open generics and I am able to register and resolve in a basic case like so: Registration: builder.RegisterGeneric(typeof(PassThroughFlattener<>)) .As(typeof(IFlattener<>)) .ContainerScoped(); Resolve: var flattener = _container.Resolve<IFlattener<Address>>(); The above code works just fine. However, assuming that I will not know the type provided to IFlattener until runtime, I want to do something like this: object input = new Address(); var flattener = (IFlattener)_container.Resolve(typeof(IFlattener<>), new TypedParameter(typeof(IFlattener<>),

Does DI make sense in a desktop app?

99封情书 提交于 2019-12-04 05:47:43
I am about to create a Desktop App (with .NET windows forms) Essentially, I want to create an n-tier app but I also want loose coupling between layers. However, I am not very sure if this is a good approach for windows forms And now I just wonder if it would be really a wise choice to use any IoC (StructureMap, Ninject, Spring.Net), I have used them before for Asp.Net web applications but what makes me doubt now is the fact that working with windows forms my business entities will persist when I navigate through tabs and unlike than web forms or mvc apps where it would be necesary to inject my

Laravel Dependency Injection in Middleware

守給你的承諾、 提交于 2019-12-04 04:36:20
I am using Laravel-5.0's default Authentication Middleware, but I changed the signature of the handle function to have: public function handle($request, Closure $next, AuthClientInterface $authClient) I also registered AuthClientInterface in a Service Provider with: public function register() { $this->app->bind('App\Services\Contracts\AuthClientInterface', function() { return new AuthClient( env('AUTH_SERVER_URL'), env('AUTH_SESSION_URL'), env('AUTH_CLIENT_ID') ); }); } However, despite this, I am see the following error: Argument 3 passed to HelioQuote\Http\Middleware\Authenticate::handle()

How to change configs in Spring.Net

谁都会走 提交于 2019-12-04 04:34:01
问题 An advantage of an IoC container is that you can swap in a mock service at the bottom of your object graph. However this seems much harder to do in Spring.Net than in other IoC Containers. Here's some code that does it in Unity and has Spring.Net code; namespace IocSpringDemo { using Microsoft.Practices.Unity; using NUnit.Framework; using Spring.Context; using Spring.Context.Support; public interface ISomeService { string DoSomething(); } public class ServiceImplementationA : ISomeService {

Castle Windsor: Force resolver to use specified constructor

人走茶凉 提交于 2019-12-04 04:12:16
Here is the example: interface IComponentA {}; class ComponentA : IComponentA { }; interface IComponentB { }; class ComponentB : IComponentB { }; interface IComponentC { }; class ComponentC : IComponentC { public ComponentC(IComponentA a) { Console.WriteLine("Constructor A"); } public ComponentC(IComponentB b) { Console.WriteLine("Constructor B"); } }; All these components are registered in Castle Windsor container. But class ComponentC has 2 overloaded constructors. Any of them can be used when ComponentC is being activated. I need ComponentC(IComponentB b) constructor to be used. For a

Castle windsor intercepter

廉价感情. 提交于 2019-12-04 04:06:04
问题 I am trying to intercept calls to the Handle method on my command handlers. this process works fine when I explicitly register each command handler, the problem is that my generic registration of the command handlers and the interceptor is not correct. exception: An exception of type 'Castle.MicroKernel.ComponentActivator.ComponentActivatorException' occurred in Castle.Windsor.dll but was not handled in user code Additional information: ComponentActivator: could not proxy TempSearch.Command