structuremap

How to setup named instances using StructureMap profiles?

我怕爱的太早我们不能终老 提交于 2020-01-15 05:51:05
问题 I've done quite a bit of googling and searching here on SO, but couldn't find a similar question or answer. In typical SM configuration you can add multiple named instances for a single PluginType: ForRequestedType<IFoo>() .AddInstances( x => { x.OfConcreteType<FooA>().WithName( "FooA" ); x.OfConcreteType<FooB>().WithName( "FooB" ); } ); No problem there. The problem is that I can't do the same when creating a profile. Most examples explaining how to use profiles use the For<>() method of the

Confusion with StructureMap 4.6 Transient Lifecycle

牧云@^-^@ 提交于 2020-01-15 03:52:04
问题 I am using StructureMap 4.6 as my IoC Container. I am a bit confused about its lifecycles. As I have read in its documentation, Transient will create a single instance of the object per container. Supported Lifecycles I am checking this scenario by creating a simple Console Application project. My code is as below: Program.cs class Program { private static IContainer _Container; static void Main(string[] args) { _Container = Container.For<ConsoleRegistry>(); var serv1 = _Container.GetInstance

AOP Logging with StructureMap

被刻印的时光 ゝ 提交于 2020-01-14 03:26:06
问题 I am trying to implement simple logging with AOP approach with StructureMap. Basically, I want to do what is asked in the question Castle, AOP and Logging in .NET with StructureMap. CastleWindsor has the helpful IInterceptor that you can implement and then control when the a method is called with the IInvocation.Proceed() . Allowing you to perform logging before and after the call to the method is made. How can achieve this with StructureMap? I have tired using a custom Interceptor but the

With StructureMap is it possible to make a Singleton object AND provide constructor arguments?

我与影子孤独终老i 提交于 2020-01-13 17:37:09
问题 I can't seem to figure out how to define a object as a singleton AND define two arguments for the constructor. I can do either / or .. just not at the same time. Eg. (this doesn't work)... ForRequestedType<IFoo>() .TheDefaultIsConcreteType<Foo>() .CacheBy(InstanceScope.Singleton) .WithCtorArg("alpha").EqualToAppSetting("Alpha") .WithCtorArg("beta").EqualToAppSetting("Beta"); Suggestions? 回答1: You are very close. The trick is that you need to use the alternate default DSL language TheDefault

With StructureMap is it possible to make a Singleton object AND provide constructor arguments?

只愿长相守 提交于 2020-01-13 17:37:04
问题 I can't seem to figure out how to define a object as a singleton AND define two arguments for the constructor. I can do either / or .. just not at the same time. Eg. (this doesn't work)... ForRequestedType<IFoo>() .TheDefaultIsConcreteType<Foo>() .CacheBy(InstanceScope.Singleton) .WithCtorArg("alpha").EqualToAppSetting("Alpha") .WithCtorArg("beta").EqualToAppSetting("Beta"); Suggestions? 回答1: You are very close. The trick is that you need to use the alternate default DSL language TheDefault

Does ASP.NET multithreading impact Structuremap singleton class?

你离开我真会死。 提交于 2020-01-13 16:25:12
问题 In my ASP.NET MVC project I have a class which is instantiated via Structuremap and is configured as a singleton. Given that ASP.NET is inherently multithreaded and the Singleton pattern is not threadsafe by default, will it cause any issues? I faced an issue where multiple instances were being returned for a class configured as Singleton. Could this problem be because of the instances being requested from different threads. EDIT : A more detailed description is given on this question

swagger UI is not showing anything in webapi

十年热恋 提交于 2020-01-13 10:04:38
问题 I followed this up to the xml doc part in order to create Swagger documentation using Swashbuckle. It should allow me to view the endpoints via (in my case): http://localhost:51854/swagger/ui/index Unfortunately, I cannot see any endpoints: Any ideas why and how to fix this? Please note that I created my webapi from an empty webapi project - maybe that's the problem. Something must be missing but I am not sure what ... I have now identified the following code as the root cause. In Global.asax

structuremap Web Api 2 Account Controller and individual accounts

无人久伴 提交于 2020-01-13 08:59:49
问题 I pretty New at IOC and web-api 2, but have got StructureMap to work on my own Controllers in web-api 2. What I don't have managed is to use StructureMap on the AccountController using Individual Accounts. I use AccountController out of the Box, and what I have managed so far is following: In Ioc.cs I have added following (Because of errors) x.For<IUserStore<ApplicationUser>>().Use<UserStore<ApplicationUser>>(); x.For<DbContext>().Use(() => new ApplicationDbContext()); x.For<ISecureDataFormat

Inject service into an AutoMapper destination class

萝らか妹 提交于 2020-01-13 08:40:07
问题 Say I have a source and destination class that is mapped using AutoMapper. The destination has a logger service injected into the constructor. However, I don't know how to get the service injected into the constructor through StructureMap? I've tried the following: Mapper.Initialize(m => { m.ConstructServicesUsing(ObjectFactory.GetInstance); }); which didn't prevent me having the exception on the mapping call, I guess because the service isn't being injected in properly. I also tried the

Injecting ISession Into My Repositories Using Structuremap in a Asp.Net MVC Application

感情迁移 提交于 2020-01-10 15:40:13
问题 My repositories all take ISession in the constructor: protected Repository(ISession session) { this.session = session; } private readonly ISession session; In an Asp.Net MVC application, using StructureMap, how would I go about setting up ISession in my the StructureMap Registry? Would I need to to add SessionFactory to the container also? Does FluentNHibernate change things? 回答1: You should register ISession using a factory method. Another options (not always the best, but easy to use) is to