structuremap

Need complete DI sample for WCF

落爺英雄遲暮 提交于 2019-12-14 03:44:11
问题 Does anyone have a complete and working DI sample for WCF? Every sample I find just gets me more confused. Does anyone know of a complete and working standalone simple sample that works with the built in stuff? Maybe once I get a handle of the built in stuff, I can move on to different DI frameworks such as StructureMap or Unity with WCF. My MVC project is currently using Unity for all its DI. 回答1: The code download for my book Dependency Injection in .NET contains a full, working example.

StructureMap resolve dependency through injection instead of service location

大城市里の小女人 提交于 2019-12-14 03:39:42
问题 In my project I register many ISerializers implementations with the assembly scanner. FWIW this is the code that registers my ISerializers Scan(scanner => { scanner.AssemblyContainingType<ISerializer>(); scanner.AddAllTypesOf<ISerializer>().NameBy(type => type.Name); scanner.WithDefaultConventions(); }); Which then correctly registers ISerializer (...ISerializer) Scoped as: Transient JsonSerializer Configured Instance of ...JsonSerializer BsonSerializer Configured Instance of ..

ASP.NET MVC4 NServiceBus Attribute/Filter StructureMap

我只是一个虾纸丫 提交于 2019-12-14 03:12:08
问题 I'm having issues getting an instance of IBus in an action filter (attribute). From Setting IBus Property in MVC Filter, I know that DI and action filters don't play nice, and I got them play nice using the accepted answer. The problem is that getting DI and action filters to play nice breaks NServiceBus. That same question had a suggestion by John to look at the video store solution to see how to get it done. There are two problems with that answer: It totally ignores the fact that I'm using

Get Instance from StructureMap by Type Name

随声附和 提交于 2019-12-13 14:50:51
问题 Is there any way to request an instance from the StructureMap ObjectFactory by the string name of the type? For example, it would be nice to do something like this: var thing = ObjectFactory.GetInstance("Thing"); The use case here is a messaging scenario in which the message is very generic and contains only the name of a task. A handler receives the message, gets the task name from the message and retrieves the type name of the associated task runner from a configuration database.

Chaining containers with StructureMap

自闭症网瘾萝莉.ら 提交于 2019-12-13 14:18:10
问题 Is it possible to link containers together in StructureMap like it is in WindsorContainer.AddChildContainer()? I want to achieve having 3 container levels; - 1 page request level - 1 session level - 1 application level These would then be chained together so only one instance request would be made to the "base level" container. The levels of container are unimportant really, just whether there is the ability to link them together. 回答1: This seems to do the trick, not sure if there is a better

StructureMap: Creation as Transient (per request) not working

ⅰ亾dé卋堺 提交于 2019-12-13 14:05:15
问题 I'm trying to solve a IoC problem, that seemed easy at first, but turned out to be a pain in the ass:-P I have a heavy weight main class, which must be initialized only once, so it's marked as Singleton. However this class uses a subclass which must be created once for each request, so it's marked as Transient: public class MyRegistry : Registry { public MyRegistry() { For<IMainClass>() .Singleton() .Use(ctx => new MainClass(() => ctx.GetInstance<ISubClass>())); For<ISubClass>() .Transient()

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

MVC 2.0, StructureMap, Areas, and Duplicate Controller Names

江枫思渺然 提交于 2019-12-13 05:14:09
问题 I have a bit of a problem. I have an area called Framed. This area has a home controller. The default for the site also has a home controller. What I'm trying to do with this is have a version of each controller/action that is suitable for an IFrame, and a version that is the normal site. I do this through Master pages, and the site masterpage has many different content place holders than the framed version. For this reason I can't just swap the master page in and out. For example, http:/

Help with structuremap configuration

僤鯓⒐⒋嵵緔 提交于 2019-12-13 04:33:45
问题 I am trying to configure Structuremap something like the following but I can seem to get it quite right ObjectFactory.Initialize(x => { x.For<TunaRepository>() .Use(new TunaRepository(serviceEndpoint)) .Named("Tuna"); x.For<CodRepository>() .Use(new CodRepository(serviceEndpoint)) .Named("Cod"); x.For<HaddockRepository>() .Use(new HaddockRepository(serviceEndpoint)) .Named("Haddock"); x.For<IFishRepository>().AddInstances(y => { y.OfConcreteType<TunaRepository>(). // Somehow add all instances

Inject ISession into custom valueresolver

孤人 提交于 2019-12-13 04:32:33
问题 I'm trying to inject an instance of ISession into a custom AutoMapper ValueResolver . Here's the resolver public class ContactTypeResolver : ValueResolver<Common.Models.ContactType, Models.ContactType> { ISession _session; public ContactTypeResolver(ISession session) { _session = session; } protected override Models.ContactType ResolveCore(Common.Models.ContactType source) { return _session.Load<Models.ContactType>(source.Id); } } I have a profile for setting up AutoMapper this.CreateMap