inversion-of-control

Register IOC container to self

房东的猫 提交于 2019-12-10 23:05:32
问题 Let's say I have an interface IDependencyResolver: public interface IDependencyResolver{ T Resolve<T>() where T: class; object Resolve(Type source); } And an implementation with the use of SimpleInjector: public class SIDependencyResolver:IDependencyResolver{ private readonly Container _container; public SIDependencyResolver(Container container){ _container = container; _container.Options.DefaultScopedLifestyle = new WcfOperationLifeStyle(); RegisterDependencies(_container, LifeStyle.Scoped);

Setting ASP.NET MVC ControllerFactory has no effect

喜欢而已 提交于 2019-12-10 21:55:10
问题 I'm trying to have my ASP.NET MVC2 controllers built using StructureMap but ASP.NET doesn't seem to remember that I've called ControllerBuilder.Current.SetControllerFactory in my Global.asax file. Specifically I get the error that my controller has no parameterless constructor. The stack trace reveals that my custom ControllerFactory was never actually executed. Here is my call to the method that should tell ASP.NET which ControllerFactory to use: Sub Application_Start() RegisterRoutes

Ninject factory extension and InCallScope does not give expected results

白昼怎懂夜的黑 提交于 2019-12-10 21:23:55
问题 I am struggling with using the factory extensions for Ninject. When using the extension in combination with InCallScope, I expected the same instance to be returned from the factory's create method, but instead I get two different instances. Have I misunderstood the InCallScope concept or do I need to add something else? using System; using Ninject; using Ninject.Extensions.Factory; using Ninject.Extensions.NamedScope; namespace MyTest { class Program { static void Main() { var kernel = new

Is Kigg MVC application DRY? Can we tweak the Repository

北城以北 提交于 2019-12-10 18:56:13
问题 I was recently taking a look at the Kazi Manzur Kigg MVC implementation (Kazi rocks) and noticed some code that seemed to defeat the DRY/SOC principle. I'd love to have everyone's thoughts on a possible refactor to separate concerns. Kigg implements both an Add and Remove method on each repository class ( Note : BaseRepository has virtual methods than can be overloaded by each concrete implementation.) The implementations for the Kigg.Repository.LinqToSql.CategoryRepository and the Kigg

Microsoft Unity - code to xml

白昼怎懂夜的黑 提交于 2019-12-10 18:44:42
问题 Can someone provide the XML configuration I should use with Microsoft Unity application block in the Enterprise Library 4.1 to achieve the same result as the following? using System; using Microsoft.Practices.Unity; using Microsoft.Practices.Unity.InterceptionExtension; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { IUnityContainer container = new UnityContainer(); container.AddNewExtension<Interception>(); container.RegisterType<ILogger, Logger>();

Programatic property injection with Microsoft Unity

可紊 提交于 2019-12-10 18:22:23
问题 I use contructor injection in my solution, but this one class has a property that i do not want to pass in the constructor where i have the invariant dependencies. Let's say i got an ILogger and it has a FileName property i want to set, while still having it set the dependancies in the contructor. How do i go about registering the type, and at the same time pass the defaunt connection string. I hope there is an easy way to do it - preferably without decorating the property with an attribute,

Traditional 3 tier architecture vs 3 tier with IOC

此生再无相见时 提交于 2019-12-10 17:25:18
问题 I am building a 3 tier architecture with a Presentation Layer (PL), Business Logic Layer (BLL) and a Data Access Layer (DAL). Conventional 3 tier architecture logic states that BLL should act as a mediator between the PL and the DAL. The PL shouldn't be even aware that there is a Database while the DAL should not be aware that there is a BLL or a PL. Implementing above would create following dependencies among the 3 different physical projects as follows PL Project -> Reference of BLL DLL BLL

How to carry out custom initialisation with autofac

泄露秘密 提交于 2019-12-10 17:21:31
问题 I'm adding autofac to an existing project and some of the service implementations require their Initialize method to be called and passed configuration information. Currently I'm using the code: builder.Register(context => { var service = new SqlTaxRateProvider(context.Resolve<IUserProvider>()); service.Initialize(config); return service; } ).As<ITaxService>() .SingleInstance(); which works but I'm still creating the object myself which is what I'm trying to get away from this and allow

Passing ASP.NET User by Dependency Injection

一个人想着一个人 提交于 2019-12-10 17:13:39
问题 In my web application I have various components that need to access the currently authenticated user (HttpContext.User). There are two obvious ways a component can access this: 1) Accessing getting the User from HttpContext.Current 2) Passing the user around in constructors Is not ideal because it makes testing difficult and ties application components to web concerns, when they really shouldn't know about it. Is just messy and complicates everything. So I've been thinking about passing in

Setting the Name property during registration of a component using Castle Windsor IoC container

穿精又带淫゛_ 提交于 2019-12-10 15:53:24
问题 In my application I have a class named Message. There exists a property in the Message class with the name MessageType of type string. The MessageType property is used to alert the application as to what data schema will exist within the instance of the Message class. The Message class derives from an interface named IMessage. As an example let's say we have an instance of the Message class who's MessageType property has the value of "com.business.product.RegisterUser". Each MessageType