structuremap

Managing RavenDB IDocumentSession lifecycles with StructureMap for NServiceBus and MVC

旧时模样 提交于 2019-12-05 08:34:44
I am using NServiceBus v4.3, MVC4, RavenDB 2.5 and StructureMap 2.6.4 in our solution. I am having a similar issue under StructureMap to that described in this question 's responses where I require different lifecycles for the MVC Controller and NServiceBus Handler use of RavenDB's IDocumentSession in my Web project. Specifically in my case what happens is that if I use the HybridHttpOrThreadLocalScoped (as the above answer suggests for Windsor) lifecycle the sessions are not properly disposed of and I soon hit the 30 transaction limit error. If I use the HttpContext lifecycle my NSB event

Structure Map - I dont want to use the greediest constructor!

瘦欲@ 提交于 2019-12-05 05:39:10
I am trying to configure the NCommon NHRepository in my project with Structure Map. How do I stop it from choosing the greediest constructor? public class NHRepository<TEntity> : RepositoryBase<TEntity> { public NHRepository () {} public NHRepository(ISession session) { _privateSession = session; } ... } My structure map configuration ForRequestedType(typeof (IRepository<>)) .TheDefaultIsConcreteType(typeof(NHRepository<>)) Cheers Jake You can set the [DefaultConstructor] Attribute for the constructor you wish as a default. In your case, setting it on the NHRepository() constructor would make

I am looking for a simple yet practical and robust IOC/DI framework for .net

天大地大妈咪最大 提交于 2019-12-05 02:28:09
问题 I am going to use it in a project with less-experienced developers so a complex framework such as Spring.NET is not an option. I was thinking about: Ninject Castle Windsor StructureMap Which would present a moderate learning curve without losing flexibility? and another question - where is the correct place to put the configuration? Since the kernel/configuration on a 3-tier ASP.NET application (not MVC!!! all examples are using MVC :) ) 回答1: The great thing about proper use of DI is that you

How to configure dependency injection with ASP.NET MVC 3 RTM

空扰寡人 提交于 2019-12-05 01:34:18
问题 I am upgrading a web app from ASP.NET 3 Preview 1 to the RTM and I am confused by the updated approach to dependency injection. I am using StructureMap for this but that's not really relevant to my question. Previously all I needed to do was as follows: x.For<IControllerFactory>().Use<DefaultControllerFactory>(); x.For<IServiceLocator>().Use(MvcServiceLocator.Current); Now it seems like I need to provide implementations of IControllerActivator, IViewPageActivator and ModelMetadataProvider

StructureMap Constructor arguments

那年仲夏 提交于 2019-12-05 00:59:17
I'm new to structureMap. How do I define constructor arguments for the following class with fluent configuration? Thanks public BlobContainer(CloudStorageAccount account , string containerName , string contentType , BlobContainerPermissions blobContainerPermissions) { } For primitive types you would go about as @ozczecho answered: For<BlobContainer>() .Use<BlobContainer>() .Ctor<string>("containerName").Is("theContainerName") .Ctor<string>("contentType").Is("theContentType"); provided that the values are known at registration time. You can do it this way for non-primitive types as well, but

SQL Azure: More Intermittent Timeouts

a 夏天 提交于 2019-12-05 00:09:58
问题 We have a set of 5 online auction systems running on Windows Azure & SQL Azure. Each system consists of a single web worker and one or more web roles. Each system is using ASP.NET MVC 3 and Entity Framework, Repository Pattern and StructureMap. The worker role is responsible for housekeeping and runs two groups of processes. One group is run every ten seconds, the other every second. Each process will likely run a database query or stored procedure. These are scheduled with Quartz.net The web

Simple but good example on how to use Dapper with Structuremap and dependency injection

六眼飞鱼酱① 提交于 2019-12-04 22:48:28
问题 I am trying to understand how to use Dependency Injection with Dapper (IDbConnection) and still being able to use built in dispose. I have found a couple of articles on the web but non that I think is easy to understand. What I am trying to figure out is how to make this simple class be testable: public class UserProfileRepository : IUserProfileRepository { private readonly IConfigRepository _configRepository; public UserProfileRepository(IConfigRepository configRepository) {

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

佐手、 提交于 2019-12-04 08:15:35
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>(); To map IRepository<Mailout> to MailoutRepository , use: var c = new Container(x => { x.Scan(scan => { // there are other options

structuremap - two implementations of same interface

夙愿已清 提交于 2019-12-04 08:07:54
问题 I have a service class with the following ctor: public class (IMessageService emailService, IMessageService smsService) { ... } and two implementations of IMessageService (email and sms). How do I configure the container to resolve this constructor correctly? Is this where named instances come in, or is that for another scenario? 回答1: You could use named instances or smart instances to solve this... // Named instances this.For<IMessageService>().Use<EmailService>().Named("emailService"); this

StructureMap - Override constructor arguments for a named instance

有些话、适合烂在心里 提交于 2019-12-04 07:42:31
Can you override the constructor arguments for a named instance, it seems you can only do it for a default instance. I would like to do: ObjectFactory.With("name").EqualTo("Matt").GetNamedInstance<IActivity>("soccer"); GetInstance behaves like GetNamedInstance when used after .With using NUnit.Framework; using NUnit.Framework.SyntaxHelpers; using StructureMap; namespace StructureMapWith { [TestFixture] public class Class1 { public interface IFooParent { IFoo Foo { get; set; } } public interface IFoo { } public class FooParentLeft : IFooParent { public IFoo Foo { get; set; } public