structuremap

How to use a convention for IRepository<T> with StructureMap mapping

╄→尐↘猪︶ㄣ 提交于 2019-12-06 03:23:24
问题 Is there a way in StructureMap to do this kind of repetitive mapping with one line or a convention? For<IRepository<Mailout>>().Use<MailoutRepository>(); For<IRepository<MailServer>>().Use<MailServerRepository>(); For<IRepository<MailoutStatus>>().Use<MailoutStatusRepository>(); For<IRepository<MailoutTemplate>>().Use<MailoutTemplateRepository>(); For<IRepository<Publication>>().Use<PublicationRepository>(); For<IRepository<Recipient>>().Use<RecipientRepository>(); 回答1: To map IRepository

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

♀尐吖头ヾ 提交于 2019-12-06 03:12:30
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? You are very close. The trick is that you need to use the alternate default DSL language TheDefault.Is.OfConcreteType ForRequestedType<IFoo>() .CacheBy(InstanceScope.Singleton) .TheDefault.Is.OfConcreteType

Ninject 3.0 MVC kernel.bind error Auto Registration

蓝咒 提交于 2019-12-06 01:53:29
Getting and error on kernel.Bind( scanner => ... "scanner" has the little error line under it in VS 2010. Cannot convert lambda expression to type 'System.Type[]' because it is not a delegate type Tyring to Auto Register like the old kernel.scan in 2.0. I can not figure out what i am doing wrong. Added and removed so many Ninject packages. completely lost, getting to be a big waste of time. using System; using System.Web; using Microsoft.Web.Infrastructure.DynamicModuleHelper; using Ninject; using Ninject.Web.Common; //using Ninject.Extensions.Conventions; using Ninject.Web.WebApi; using

Does ASP.NET multithreading impact Structuremap singleton class?

雨燕双飞 提交于 2019-12-05 20:02:41
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. Structuremap in Singleton returning multiple instances EDIT2 : Here is a description of what my class does

Named singleton instance in StructureMap (Multiple nHibernate session factories)

心不动则不痛 提交于 2019-12-05 18:01:46
I have a scenario where I have two Nhibernate SessionFactorys I need to register an use with StructureMap. Only Foo needs mySessionFactory sessions. Like this: For<ISessionFactory>().Singleton().Use(NHibernateConfiguration.GetDefaultSessionFactory()); For<ISession>().HybridHttpOrThreadLocalScoped().Use(x => x.GetInstance<ISessionFactory>().OpenSession()); For<ISessionFactory>().Singleton().Use(AnotherNHibernateConfiguration.GetDefaultSessionFactory).Named("mySessionFactory"); For<ISession>().HybridHttpOrThreadLocalScoped().Use(x => x.GetInstance<ISessionFactory>("mySessionFactory").OpenSession

Using StructureMap, is one of these project organizations better than another?

﹥>﹥吖頭↗ 提交于 2019-12-05 17:38:19
I'm starting to work with StructureMap on a windows application project. In working on learning the basics, I found 2 ways to arrange my solution that accomplish the same goal, and I'm wondering if anyone can comment on if one of these 2 seems like a better option, and why. The goal here was to use IOC so that I could use 2 services without taking dependencies on them. So I I created interfaces in my Business Layer, and then implemented those interfaces in my Infrastructure project and wrapped the actual services at that point. In my fist attempt at this, I created a project DependencyResolver

Action Filter Dependency Injection in ASP.NET MVC 3 RC2 with StructureMap

蹲街弑〆低调 提交于 2019-12-05 16:43:00
问题 I've been playing with the DI support in ASP.NET MVC RC2. I have implemented session per request for NHibernate and need to inject ISession into my "Unit of work" action filter. If I reference the StructureMap container directly (ObjectFactory.GetInstance) or use DependencyResolver to get my session instance, everything works fine: ISession Session { get { return DependencyResolver.Current.GetService<ISession>(); } } However if I attempt to use my StructureMap filter provider (inherits

Structuremap and generic types

女生的网名这么多〃 提交于 2019-12-05 15:33:46
I have a situation which seems a bit different from others I've seen. For clarrification, this isn't the normal question eg; something like IAClass maps to AClass etc - that involves using basically a single concrete classes per interface. This involves having a single generic class, but I want to be able to load ALL possible usages of it. Eg - the main class is of public class MyClass<TDomainObject> : IMyClass<TDomainObject> where TDomainObject : DomainObject So example usages would be IMyClass<Person> p = new MyClass<Person>; IMyClass<Employer> p = new MyClass<Employer>; I.e. for all

How to get the Structuremap IContainer instance from Asp.Net MVC 5 Dependency Resolver

不羁岁月 提交于 2019-12-05 10:17:40
I am using Structuremap as my Dependency Resolver. I am trying to implement Container Per Request Pattern on my Global.asax.cs file. public IContainer Container { get { return (IContainer)HttpContext.Current.Items["_Container"]; } set { HttpContext.Current.Items["_Container"] = value; } } public void Application_BeginRequest() { Container = ObjectFactory.Container.GetNestedContainer(); } As the ObjectFactory will not be supported in the future versions of Structuremap I would like get access to the container from the DependencyResolver. How is possible? Thanks in Advance. Noufal Having ran

swagger UI is not showing anything in webapi

橙三吉。 提交于 2019-12-05 09:43:57
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.cs: var container = new XyzWebApiStructureMapContainerConfigurator().Configure(GlobalConfiguration