structuremap

What conventions/idioms/patterns are you using configuring IOC Containers using the new Fluent Interfaces

被刻印的时光 ゝ 提交于 2019-12-09 04:53:27
问题 I am in the middle of moving over a large body of code to Castle Trunk which includes the new fluent interface for configuring the container. Since the project has a huge windsorConfig xml file that is beyond maintainable, I thought I would start to take advantage of this new feature. I know other containers (e.g. StructureMap 2.0) also contain fluent interfaces for container configuration, so this question isn't based around Windsor. My question is what conventions/idioms/patterns are you

Custom construction with open generics in StructureMap

不羁岁月 提交于 2019-12-08 09:54:44
问题 I know that for structuremap you can register generic types by specifying the following: StructureMapConfiguration .For(typeof(IRepository<>)) .Use(typeof(RepositoryImplementation<>)); When ObjectFactory.GetInstance<IRepository<Entity>>() is called the corresponding implementation is returned RepositoryImplementation<Entity> . But what if I want a wrapped version of the repository? A version that also implements IRepository<Entity> - lets say CachedRepository<Entity> that has a constructor

Using StructureMap for dependency injection to SignalR 2.0.1

ぃ、小莉子 提交于 2019-12-08 08:34:32
I'm trying to use StructureMap for dependency injection to a SignalR hub. Many sources in the internet say this should be done as in this answer: How do you Resolve signalR v2.0 with StructureMap v2.6 . I tried it, and got it to work - at least for the first action after the first pageload. When I try to leave the HTML page that includes the SignalR-JS-Code (or reload the page), or when I use one of the functions defined in my hub a second time, I get this StructureMapException: You cannot use the HttpContextLifecycle outside of a web request. Try the HybridLifecycle instead. in the public

Define default constructor with StructureMap without providing arguements or using DefaultConstructor attribute

女生的网名这么多〃 提交于 2019-12-08 06:30:08
问题 I've been using StructureMap for sometime now but I'm far from an expert. My problem is simple, I'm trying to configure SM via code (Registry) to use a particular constructor when creating an instance of a repository object. Here are my 2 constructors (note neither is the greediest). public BusinessUnitRepository( IDatabase database ) : base( database ) { } public BusinessUnitRepository( IDatabaseFactory factory ) : base( factory ) { } Note: The first constructor takes an instance of the

dynamic connection string for injected repository

烈酒焚心 提交于 2019-12-08 05:48:45
问题 I'm building a multi tenant (db per tenant) application. the application - .net MVC4 the data layer entity framework code first repositories the repositories are injected into the application via structure map The structuremap config: var connectionString = ConfigurationManager.ConnectionStrings["AccessControlDB"].ToString(); ObjectFactory.Initialize(x => { x.For<IAccessControlContext>().Use<AccessControlContext>().Ctor<string>("connectionString").Is(connectionString); x.For

Using StructureMap for dependency injection to SignalR 2.0.1

随声附和 提交于 2019-12-08 05:23:17
问题 I'm trying to use StructureMap for dependency injection to a SignalR hub. Many sources in the internet say this should be done as in this answer: How do you Resolve signalR v2.0 with StructureMap v2.6. I tried it, and got it to work - at least for the first action after the first pageload. When I try to leave the HTML page that includes the SignalR-JS-Code (or reload the page), or when I use one of the functions defined in my hub a second time, I get this StructureMapException: You cannot use

How do you output the context class using log4net as a service?

你说的曾经没有我的故事 提交于 2019-12-08 03:58:13
问题 I am using Log4Net as a service which is injected into other services using StructureMap. How do I ensure the log file includes the calling service class context (class name and/or thread) which is making the log4net calls? Surely the calling class or thread will always be the logging service which doesn't help me understand where the logging calls are really coming from. EDIT: Register code: ObjectFactory.Initialize(x => { x.For<ILog>().AlwaysUnique().Use(s => s.ParentType == null ?

How do you resolve instances of IInterceptionBehavior from the container when using StructureMap DynamicProxyInterceptor?

和自甴很熟 提交于 2019-12-08 03:30:11
问题 I'm migrating from Unity to StructureMap. I've made some use of Unity's InterceptionBehavior. I thought I could switch that to use StructureMap .InterceptWith and the DynamicProxyInterceptor but my interceptors have dependencies and I can't work out how to compose the interceptors using StructureMap. var container = new Container(x => { x.For<IMathService>().Use<MathService>() .InterceptWith(new DynamicProxyInterceptor<IMathService>(new IInterceptionBehavior[] { // I WANT TO COMPOSE THESE

Asp.Net MVC Custom Validation Attribute With StructureMap

我是研究僧i 提交于 2019-12-08 02:16:49
问题 I have a custom attribute in asp.net mvc and use structure map. how can I inject ContextDB into the custom ValidationAttribute? [AttributeUsage(AttributeTargets.Property)] public class CustomValidationAttribute : ValidationAttribute { public ContextDB _Context { get; set; } protected override ValidationResult IsValid(object value, ValidationContext validationContext) { Settings settings = new Settings(_Context); // Checking... return ValidationResult.Success; } } my code doesn't work,

Releasing ObjectContext while using StructureMap

ぃ、小莉子 提交于 2019-12-08 01:18:23
问题 I've been using StructureMap to inject ObjectContext (entities) into my repositories along with lazy-loaded POCO classes. This is my Structuremap registration. For<WebEntities>().LifecycleIs(new HybridLifecycle()).Use(()=>new WebEntities()); I have defined Partial classes against my POCO classes to retrieve info that is not defined in my EDMX schema. e.g. Community.FloorPlanImages would be a getter which filters only the floor plan images from all available Images. Worked pretty well until I