inversion-of-control

How to Make Alternative Use of Interfaces for Wcf Contracts

≯℡__Kan透↙ 提交于 2019-12-06 09:53:20
问题 Lets say I have 3 assemblies, Example.Core, Example.Contracts, Example.WcfServices. In my contracts assembly I define an interface and add some operation, e.g. ICalculator, which has operation Add(double a, double b). In my WcfServices assembly I have an implementation of ICalculator explosed as a Wcf service. Now my question is this....in my Example.Core assembly how do I program against that interface while keeping everything decoupled (to allow me to have an alternative implementation of

Reuse same instance of prototype bean twice - Spring

徘徊边缘 提交于 2019-12-06 09:33:14
问题 I have a problem with Spring: I need to reuse the same instance of bean twice, but not making it singleton. Here is a brief ApplicationContext: <bean class="a.b.c.Provider" id="defaultProvider" scope="prototype"> <constructor-arg ref="lifecycle" /> <constructor-arg ref="propertySetter" /> </bean> <bean name="lifecycle" class="a.b.c.Lifecycle" scope="prototype"> <constructor-arg ref="someParam" /> ... and more args </bean> <bean id="propertySetter" class="a.b.c.PropertySetter" scope="prototype

Custom principal in ASP.NET MVC

余生长醉 提交于 2019-12-06 08:22:14
问题 I want to be able to access custom properties for an authenticated user like UserId and FirstName without querying the database each time. I found this site through a post on Stack Overflow and I like the approach - but I use IoC / repositories and decided not to try and get global.asax to communicate with the database for fear that it would be incompatible with the repository pattern. Instead, I created an interface to CustomPrincipal and I use IoC (Castle) to create an instance and pass it

Is it possible to use Dependency Injection/IoC on an ASP.NET MVC FilterAttribute?

早过忘川 提交于 2019-12-06 08:09:12
I've got a simple custom FilterAttribute which I use decorate various ActionMethods . eg. [AcceptVerbs(HttpVerbs.Get)] [MyCustomFilter] public ActionResult Bar(...) { ... } Now, I wish to add some logging to this CustomFilter Action .. so being a good boy, I'm using DI/IoC ... and as such wish to use this pattern for my custom FilterAttribute . So if i have the following... ILoggingService and wish to add this my custom FilterAttribute .. i'm not sure how. Like, it's easy for me to do the following... public class MyCustomFilterAttribute : FilterAttribute { public MyCustomFilterAttribute

Unity 2.0 IOC Configuration about Generic class

走远了吗. 提交于 2019-12-06 07:46:34
I want some Repository class extend one common generic class to perform some common operation, problem is: how to config a UserExRepository type in config file. public class UserExRepository : Repository<User>, IUserEx { public UserExRepository(Context context):base(context){ } } public abstract class Repository<TObject> : IRepository<TObject> where TObject : class { protected Context Context = null; public Repository(Context context) { Context = context; } // do some common operation about entity, like create, delete... } You can configure binding generic to generic, generic to non-generic,

Dependency Inversion Principle and where to put the interfaces

半世苍凉 提交于 2019-12-06 07:10:44
问题 I am building a simple MVC application in asp.net. I want to follow the dependency inversion principle and I don't know if I am doing it right. I am currently working on the Authentication system. I have an AccountController which uses the Authenticator service inside. The Authenticator service is injected into the controller by constructor injection. public class AccountController : Controller { private IAuthenticator _authenticator; public AccountController(IAuthenticator authenticator) {

configuration settings and IoC

筅森魡賤 提交于 2019-12-06 06:15:54
I use IoC (DI) approach and usually have parameters, which are being read from configuration settings (i.e. connection strings, static values etc) by the lowest layer (DB layer etc). What is the best way to do it? Read directly in this the lowest layer, i.e.: string sendGridApiKey = ConfigurationManager.AppSettings["SendGridApiKey"]; It works, but need to add also this key to config file of unit test project. Also, assembly depends on configuration file Read it in the highest layer (i.e. web application) and throw as parameter from the all layers? It will work, but all middle layers will get

Using IOC in a remoting scenario

本秂侑毒 提交于 2019-12-06 06:00:43
问题 I'm struggling with getting IOC to work in a remoting scenario. I have my application server set up to publish Services (SingleCall) which are configured via XML. This works just like this as we all know: RemotingConfiguration.Configure(ConfigFile, true); lets say my service looks like that (pseudocode) public class TourService : ITourService { IRepository _repository; public TourService() { _repository = new SqlServerRepository(); } } But what I rather would like to have sure looks like this

MassTransit and Simple Injector [closed]

你说的曾经没有我的故事 提交于 2019-12-06 05:30:01
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I'm reviewing the MassTransit Distributed Application Framework for .NET. According to the website MassTransit has been built from the beginning with the concept of an IoC container being involved and provides

NInject Extension Factory

我的梦境 提交于 2019-12-06 05:16:46
After reading the new documentation on NInject v3 and how to use the Factory Extension , apparently I still don't get it fully since my code throws exceptions all over the place... I get this Exception, i could paste the whole thing if people would like that but i'll try and keep it short for now. Error activating IDeployEntityContainer No matching bindings are available, and the type is not self-bindable. Here is my code... The Ninject Bind Module class class MyNinjectModule : NinjectModule { public override void Load() { ... Bind<IDeployEntityFactory>().ToFactory(); Bind