structuremap

First try StructureMap and MVC3 via NuGet

三世轮回 提交于 2019-12-04 07:10:26
I'm trying to figure how to config StructureMap for ASP.NET MVC3 I've already using NuGet and I notice that it creates App_Start Folder with a cs file named as StructuremapMVC, so I check it and notice that is the same code but simplified that will be written manually on App_Start section placed on Global.asax... This is my code from IoC Class public static class IoC { public static IContainer Initialize() { ObjectFactory.Initialize(x => { x.Scan(scan => { scan.TheCallingAssembly(); scan.WithDefaultConventions(); scan.AddAllTypesOf<IController>(); }); x.For<OpcionDB>().Use(() => new

Structuremap in Singleton returning multiple instances

淺唱寂寞╮ 提交于 2019-12-04 06:27:05
I have registered 5 derived classes for the same interface using named instances. All these classes are registered as Singleton For<IBaseInterface>().Singleton().Use<DerivedClass1>().Named("Derived1"); For<IBaseInterface>().Singleton().Use<DerivedClass2>().Named("Derived2"); For<IBaseInterface>().Singleton().Use<DerivedClass3>().Named("Derived3"); There is a static class which resolves the instance based on input. However I observed that every call to ObjectFactory.GetInstance returns new instances on every request instead of a Singleton. There are no threads in the application as well. Any

How can I configure Structuremap to auto scan type in Assembly and Cache by Singleton?

ⅰ亾dé卋堺 提交于 2019-12-04 05:47:55
I am using mvc.net with StructureMap to scan and register all repositories and services for me. Now I want to register and cache by Singleton. How can I do? IContainer container = new Container(x => { // Register Repositories and Services x.Scan(y => { y.AssemblyContainingType<SomeRepository>(); y.AssemblyContainingType<SomeService>(); y.IncludeNamespaceContainingType<SomeRepository>(); y.IncludeNamespaceContainingType<SomeService>(); }); // Register Controllers x.Scan(y => { y.TheCallingAssembly(); y.AddAllTypesOf<IController>().NameBy(type => type.Name.Replace("Controller", "")); }); });

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

ぐ巨炮叔叔 提交于 2019-12-04 05:01:16
问题 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. 回答1: 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

Why does Nhibernate share the session across multiple requests in my MVC application?

冷暖自知 提交于 2019-12-04 04:09:37
问题 We have an MVC project that constructs the NHibernate dependecies via StructureMap like this var sessionFactory = ConnectionRegistry.CreateSessionFactory<NHibernate.Context.WebSessionContext>(); For<ISessionFactory>().Singleton().Use(sessionFactory); For<INHibernateSessionManager>().Singleton().Use<NHibernateWebSessionManager>(); The ConnectionRegistry.CreateSessionFactory looks like this public static ISessionFactory CreateSessionFactory<T>() where T : ICurrentSessionContext { if (

What do I do when ASP.NET 5 (vNext) can't redirect bindings?

亡梦爱人 提交于 2019-12-04 04:00:51
问题 I am just getting my feet wet with MVC 6. I installed VS 2015 and with the default ASP.NET 5 preview MVC Web Application template everything runs fine under local IIS. I then tried to switch out the Default DI container with StructureMap following these instructions exactly (note it is a very recent article). The only thing is I had to figure out the namespaces to import myself (since the author neglected to include them) and this is what I included. I put the StructureMapRegistration class

StructureMap and scanning assemblies

强颜欢笑 提交于 2019-12-04 03:12:00
So, I have a .NET solution that uses StructureMap, and I'd like to have StructureMap read an outside assembly that implements an interface from a project in that solution and defines the registry entry for it. StructreMap configuration for my solution: ObjectFactory.Initialize(registry => { registry.Scan(assembly => { assembly.TheCallingAssembly(); //Telling StructureMap to sweep a folder called "extensions" directly //underneath the application root folder for any assemblies found in that folder assembly.AssembliesFromPath("extensions", addedAssembly => addedAssembly.GetName().Name.ToLower()

Using StructureMap with unit tests

跟風遠走 提交于 2019-12-04 00:32:46
问题 I'm using StructureMap in a web project for DI IOC. It works perfect, but I don't have a clue how to write unit tests with StructureMap. Should I do this in AssemblyInitialize start Configuration of StructureMap like in global.asax except for datacontext not to use live LinqToSqlDataContext but some memory data like this: [AssemblyInitialize] public static void Start() { ObjectFactory.Configure(x => { x.For<IDataContext>().HttpContextScoped().Use<MemoryDataContext>() .Ctor<string>(

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

那年仲夏 提交于 2019-12-03 20:50:43
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 :) ) Mark Seemann The great thing about proper use of DI is that you can defer the decision about which DI Container to use until the last responsible moment . In

Issues with my MVC repository pattern and StructureMap

流过昼夜 提交于 2019-12-03 19:19:28
问题 I have a repository pattern i created on top of the ado.net entity framework. When i tried to implement StructureMap to decouple my objects, i kept getting StackOverflowException (infinite loop?). Here is what the pattern looks like: IEntityRepository where TEntity : class Defines basic CRUD members MyEntityRepository : IEntityRepository Implements CRUD members IEntityService where TEntity : class Defines CRUD members which return common types for each member. MyEntityService : IEntityService