structuremap3

How DI frameworks resolve dependency for same Interface with multiple configuration?

左心房为你撑大大i 提交于 2020-01-22 02:02:38
问题 Consider below code sample: public interface IMyInterface { void SetName(string name); string GetName(); } public class MyInterfaceImplementor1 : IMyInterface { protected string Name { set; get; } public void SetName(string name) { this.Name = name; } public virtual string GetName() { return this.Name; } } public class MyInterfaceImplementor2 : MyInterfaceImplementor1 { public override string GetName() { return String.Format("Hello! {0}", base.Name); } } And the DI configuration for this: (

What is the equivalent of HybridHttpOrThreadLocalScoped in structure map 3?

天涯浪子 提交于 2020-01-02 00:54:10
问题 With structuremap 2.6.4.1 my container is configured like this: existingContainer.Configure(expression => { expression.For<IDocumentSession>() .HybridHttpOrThreadLocalScoped() .Use(container => { var store = container.GetInstance<IDocumentStore>(); return store.OpenSession(); }); } HybridHttpOrThreadLocalScoped does not exist in structure map 3 so my question is, what is the equivalent configuration in structuremap 3? 回答1: As of StructureMap 3, anything HttpContext related lives within a

Passive Attributes and Nested Containers

让人想犯罪 __ 提交于 2019-12-18 09:47:12
问题 Final Solution With help from @NightOwl888's answer, here's the final approach I went with for anyone who ends up here: 1) Added the global filter provider: public class GlobalFilterProvider : IFilterProvider { public IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) { var nestedContainer = StructuremapMvc.StructureMapDependencyScope.CurrentNestedContainer; foreach (var filter in nestedContainer.GetAllInstances<IActionFilter>()) { yield

No default instance or named instance 'Default' for requested plugin type

早过忘川 提交于 2019-12-13 05:19:45
问题 I'm trying to avoid referencing the concrete type library in my main project, but I'm getting this error: No default instance or named instance 'Default' for requested plugin type StackExchangeChatInterfaces.IClient 1.) Container.GetInstance(StackExchangeChatInterfaces.IClient ,{username=; password=; defaultRoomUrl=; System.Action`2[System.Object,System.Object]=System.Action`2[System.Object,System.Object]}) I've setup my container to scan for assemblies, like so: var container = new Container

StructureMap GetAllInstances on Open Generic Types

↘锁芯ラ 提交于 2019-12-13 00:26:52
问题 I'm new to StructureMap and trying out a simple scenario I scan for all assemblies in the base folder and look for types implementing my open generic interface. Scan( scan => { scan.AssembliesFromApplicationBaseDirectory(); scan.AddAllTypesOf(typeof(IHandler<>)); }); This works and I can see it registering all such types, but when it comes to getting a list of all types I am facing issues where below statement returns null. var list = container.GetAllInstances(typeof(IHandler<>)); However, I

TypeInterceptor replacement for Structuremap 3

时间秒杀一切 提交于 2019-12-12 05:13:43
问题 Can't seem to find any useful guide on how to reproduce the functionality currently provided by a TypeInterceptor in my codebase when upgrading from StructureMap 2 to version 3 (can't upgrade to v4 as we aren't using .NET 4.6 yet). Essentially what the interceptor does is this: public class TheInterceptor : TypeInterceptor { private Dictionary<string, string> typesToIntercept; public TheInterceptor(IDictionary<string, string> typesToIntercept) { // Passed in on ctor, comes from XML

StructureMap3 How to configure constructor string injection for all types?

荒凉一梦 提交于 2019-12-12 03:19:44
问题 I have registered my types using Scan( scan => { scan.TheCallingAssembly(); scan.WithDefaultConventions(); scan.With(new ControllerConvention()); }); But how do I specify for constructor injection with out having to specify the concrete type like this? string connStr = "..."; For<IRepository().Use<MyRepository>().Ctor<string>("connectionString").Is(connStr); 回答1: You can create dedicated convention for registration of repositories. public class RepositoryConvention : IRegistrationConvention {

Structuremap3 DecorateAllWith

試著忘記壹切 提交于 2019-12-11 09:07:02
问题 I've been struggling getting DecorateAllWith working on generic interfaces. I've read some posts here where they solved it using interceptors but they seem to be using an older structure map version and it doesn't seem like a "clean" solution. I would really need some help to get it working with structure map 3 I have a generic repository which i would like to decorate with both logging and caching public interface IEntityRepository<T> where T : Entities.IEntity { } I have about 20 interfaces

How do I use Structuremap 3 with objects that aren't friendly to constructor injection?

南楼画角 提交于 2019-12-07 22:06:49
问题 I'm moving from StructureMap 2.x to 3.x. One major change is that using ObjectFactory results in the following warning: 'StructureMap.ObjectFactory' is obsolete: 'ObjectFactory will be removed in a future 4.0 release of StructureMap. Favor the usage of the Container class for future work' So in most cases, the resolution is fairly easy: pass through IContainer as a constructor. Unfortunately this is not feasible for ASMX web serivces or attributes, both of which require a default constructor.

How do I use Structuremap 3 with objects that aren't friendly to constructor injection?

人盡茶涼 提交于 2019-12-06 11:43:52
I'm moving from StructureMap 2.x to 3.x. One major change is that using ObjectFactory results in the following warning: 'StructureMap.ObjectFactory' is obsolete: 'ObjectFactory will be removed in a future 4.0 release of StructureMap. Favor the usage of the Container class for future work' So in most cases, the resolution is fairly easy: pass through IContainer as a constructor. Unfortunately this is not feasible for ASMX web serivces or attributes, both of which require a default constructor. That means I'm probably stuck with the Service Locator Pattern , property injection, or writing my own