structuremap

Entity Framework : Change connection string at runtime

会有一股神秘感。 提交于 2019-12-03 01:42:23
Assuming there is an ASP.NET MVC application that uses Entity Framework 6 with code-first approach and StructureMap as IoC. Also It uses Unit Of Work pattern. Here are the codes : Domain Class public class Product { public int Id { get; set; } public string Name { get; set; } public decimal Price { get; set; } } IUnitOfWork and DbContext : public interface IUnitOfWork { IDbSet<TEntity> Set<TEntity>() where TEntity : class; int SaveChanges(); } public class Sample07Context : DbContext, IUnitOfWork { public DbSet<Product> Products { set; get; } #region IUnitOfWork Members public new IDbSet

How to dispose resources with dependency injection

此生再无相见时 提交于 2019-12-03 01:14:47
I'm using StructureMap to resolve references to my repository class. My repository interface implements IDisposable, e.g. public interface IMyRepository : IDisposable { SomeClass GetById(int id); } An implementation of the interface using Entity Framework: public MyRepository : IMyRepository { private MyDbContext _dbContext; public MyDbContext() { _dbContext = new MyDbContext(); } public SomeClass GetById(int id) { var query = from x in _dbContext where x.Id = id select x; return x.FirstOrDefault(); } public void Dispose() { _dbContext.Dispose(); } } Anyway as mentioned I'm using StructureMap

using (Fluent) NHibernate with StructureMap (or any IoCC)

狂风中的少年 提交于 2019-12-03 00:40:22
On my quest to learn NHibernate I have reached the next hurdle; how should I go about integrating it with StructureMap? Although code examples are very welcome, I'm more interested in the general procedure. What I was planning on doing was... Use Fluent NHibernate to create my class mappings for use in NHibs Configuration Implement ISession and ISessionFactory Bootstrap an instance of my ISessionFactory into StructureMap as a singleton Register ISession with StructureMap, with per-HttpRequest caching However, don't I need to call various tidy-up methods on my session instance at the end of the

StructureMap, NHibernate and multiple databases

若如初见. 提交于 2019-12-03 00:29:31
I'm working on an Asp.Net MVC 3 application using Fluent NHibernate. I'm just attempting to add an IoC container using StructureMap. I have implemented a custom controller factory which uses StructureMap to create the controller and inject dependencies. Each controller constructor takes one or more services, which in turn take a DAO as constructor argument. Each DAO constructor takes an ISessionFactory. For my StructureMap NHibernate registry I have the following: internal class NHibernateRegistry : Registry { public NHibernateRegistry() { var connectionString = ConfigurationManager

NLog GetCurrentClassLogger() NullReferenceException using StructureMap (Full Trust)

只愿长相守 提交于 2019-12-02 23:34:14
It seems like NLog can't use reflection for GetCurrentClassLogger() , even though my MVC 3 app is deployed in a Full Trust environment on IIS7. I'm using StructureMap 2.6.1 and the problem seems to appear sporadically between deploys. I can't figure out why, though I don't think StructureMap is causing it. Bootstrapper class: public static class Bootstrapper { public static void ConfigureStructureMap() { ObjectFactory.Initialize(Init); } private static void Init(IInitializationExpression x) { x.AddRegistry(new DBServiceRegistry()); x.AddRegistry(new MyRegistry()); } } Registry class: public

structuremap - two implementations of same interface

百般思念 提交于 2019-12-02 22:16:45
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? NightOwl888 You could use named instances or smart instances to solve this... // Named instances this.For<IMessageService>().Use<EmailService>().Named("emailService"); this.For<IMessageService>().Use<SmsService>().Named("smsService"); // Smart instances var

StructureMap Tutorial [closed]

对着背影说爱祢 提交于 2019-12-02 17:35:17
I am look for some Structure map Tutorials. Does anyone know of any? EDIT: All answers are appreciated but I was looking for something that is not on the first 2 pages of Google. I would have the sense to do that first. eglasius Read http://structuremap.sourceforge.net/QuickStart.htm . And from there you can find info of plenty of different usages. Update 1: I had been using structuremap, and the info in there was just enough to get it going. Also note that I am biased for text formats, although I do listen/watch other formats from time to time. That said, here are some extra info on it that I

How to scan and auto-configure profiles in AutoMapper?

浪子不回头ぞ 提交于 2019-12-02 17:12:15
Is there any way to auto-configue Automapper to scan for all profiles in namespace/assembly? What I would like to do is to add mapping profiles to AutoMapper from given assembly filtered by given interface, something like Scan Conventions in StructureMap: public static void Configure() { ObjectFactory.Initialize(x => { // Scan Assembly x.Scan( scanner => { scanner.TheCallingAssembly(); scanner.Convention<MyCustomConvention>(); scanner.WithDefaultConventions(); }); // Add Registries x.AddRegistry(new SomeRegistry()); }); Debug.WriteLine(ObjectFactory.WhatDoIHave()); } public class

Does MS PnP Unity Scan for Assemblies Like StructureMap?

烈酒焚心 提交于 2019-12-02 11:54:59
问题 In Using StructureMap 2.5 to scan all assemblies in a folder, we can see that StructureMap uses AssembliesFromPath() to explicitly look for types to resolve. What is the equivalent of this in Microsoft Unity? Because Unity is such a generic term, searching for documents about this online is not that easy. Update: Unity has something called an Assembly Matching Rule but its description does not communicate to me that it scans folders . 回答1: The Assembly Matching Rule is used for applying

What version of StructureMap can I use in webform app (Net 2.0)

走远了吗. 提交于 2019-12-02 06:01:22
I am bit confuse. I would like to use StructureMap in my webform app, but it is still Net 2.0. I am not really sure which version I should use. Anyone using StructureMap for Net 2.0 project? Which version? Thanks for any response. X. I believe that you have to use Structure Map 2.0 or earlier. 来源: https://stackoverflow.com/questions/1666151/what-version-of-structuremap-can-i-use-in-webform-app-net-2-0