unity-container

An example of a bootstrapper file?

为君一笑 提交于 2020-01-04 05:17:13
问题 Does anyone have a good example of a bootstrapper class I can see for reference.. I can't seem to find one anywhere, searched google but no luck. Searched the helpfile and no luck.. 回答1: If you are searching for a class that that configures the container at the beggining of an application, you can download the latest Prism drop and look for the UnityBootstrapper class. Take into account that this is only registering the necessary services for a Prism application to run, so your bootstrapper

Abstract Factory with Unity

▼魔方 西西 提交于 2020-01-04 03:04:50
问题 I have a simple Abstract Factory implementation: public abstract class ICarFactory{ public abstract ISportsCar CreateSportCar(); public abstract IFamilyCar CreateFamilyCar(); } public abstract class ISportsCar { public abstract void Accelerate(); } public abstract class IFamilyCar { public abstract void Accelarete(); } public class BMWFactory : ICarFactory { public override ISportsCar CreateSportCar() { return new BMWi7(); } public override IFamilyCar CreateFamilyCar() { return new BMWM5(); }

Unity Interception GetCustomAttribute

Deadly 提交于 2020-01-04 01:53:53
问题 Thanks in advance for your help! (Yes, there's a question at the bottom) I'm using Unity 3.x Interception to perform AOP pre and post database connection and transaction activities. The database interceptor is always instantiated and the transaction interceptor is CustomAttributeMatchingRule based, both via InterfaceInterceptor. I have properties that are being set in my TransactionAttribute: [Transaction(IsolationLevel.ReadUncommitted, NoRollbackFor = new[] { typeof(TestException) })] as an

ServiceLocator get instance by passing construction parameter

孤街浪徒 提交于 2020-01-03 15:34:17
问题 How can I get object instance with service locator with the constructor below. ProductCode is the constructor parameter used to initialize member properties. For all other constructor parameters, I have registered them using unity in the global.asax file. Basic way to get object instance if constructor parameters are reference type: var productSettingsRepo = ServiceLocator.Current.GetInstance<ProductSettingsRepository>(); public ProductSettingsRepository(ILogWriter logWriter,

How to dispose the object created by Unity DI right after the completing the request?

时光怂恿深爱的人放手 提交于 2020-01-03 13:03:03
问题 I want to know if there is a better to way to handle this. I've set up Unity for dependency injection for our project. The project itself is an ASP.NET application that uses Web API. I have the following packages installed. Unity Unity.ASPNet.WebAPI I see no option to close/dispose the DBContext right after fetching the data. My controller public class NinjasController : ApiController { public Ninja Get(int id) { INinjaRepository repository = UnityConfig.Container.Resolve(typeof

How to dispose the object created by Unity DI right after the completing the request?

时光怂恿深爱的人放手 提交于 2020-01-03 13:02:09
问题 I want to know if there is a better to way to handle this. I've set up Unity for dependency injection for our project. The project itself is an ASP.NET application that uses Web API. I have the following packages installed. Unity Unity.ASPNet.WebAPI I see no option to close/dispose the DBContext right after fetching the data. My controller public class NinjasController : ApiController { public Ninja Get(int id) { INinjaRepository repository = UnityConfig.Container.Resolve(typeof

Depedency injection: injecting partially-initialized objects

拜拜、爱过 提交于 2020-01-03 10:42:06
问题 This question is about Unity Container but I guess it is applicable to any dependency container. I have two classes with circular dependencies: class FirstClass { [Dependency] public SecondClass Second { get; set; } } class SecondClass { public readonly FirstClass First; public SecondClass(FirstClass first) { First = first; } } Technically it's possible to instantiate and correctly inject dependencies for both of them if treat them as singletons: var firstObj = new FirstClass(); var secondObj

Getting error “Association references unmapped class” when using interfaces in model

丶灬走出姿态 提交于 2020-01-03 05:43:04
问题 I'm trying to use the automap functionality in fluent to generate a DDL for the following model and program, but somehow I keep getting the error "Association references unmapped class: IRole" when I call the GenerateSchemaCreationScript method in NHibernate. When I replace the type of the ILists with the implementation of the interfaces (User and Role) everything works fine. What am I doing wrong here? How can I make fluent use the implemented versions of IUser and IRole as defined in Unity?

Need help implementing Command Handlers/Bus using Unity DI

时间秒杀一切 提交于 2020-01-03 02:04:17
问题 Folks, I am trying to re-factor a legacy brownfield application into a CQRS architecture with commands and a command bus for domain modifications. The application will more than likely be implemented in Asp.Net MVC3. My employer prefers the use of Unity for DI in MVC applications. Any examples I can find showing a dependency container for command/bus resolution are based on Structuremap or Autofac, however I will need to use Unity in this implementation. Has anyone used Unity in this manner

How can I inject a property only if the value is non-null at runtime using Unity?

独自空忆成欢 提交于 2020-01-03 01:43:27
问题 I have an interface to resolve and one of the mapped object's dependencies has a property on it which I would like to set with a value that I only have available when I resolve the top level object. There's no valid default value for the property. If its not set it should be null and it should only be set if the value that I have available at resolve time is not null. Is this conditional property injection possible? I tried this... container.RegisterType<ProductInstanceValidatorBase,