structuremap

Dependency Injection for DAL with multiple database strings using StructureMap

爷,独闯天下 提交于 2019-12-13 02:19:23
问题 I have an application that uses Structuremap for DI for both my business and DAL layer. Up to this point, I have had a single DAL per environment that I have been working on. So I would grab it from the config and use that value for all my connections. An example of this is. using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Database"].ToString())) { //Do a call to db here. } I am calling this method using structure map as follows. ObjectFactory.GetInstance

How to access UserProfile in _Layout View

别说谁变了你拦得住时间么 提交于 2019-12-13 01:58:08
问题 In my MVC application I have a shared _Layout.cshtml file that displays the menu for a User On that View I want to display information from the UserProfile entity - created using SimpleMembership and thus linked to the IPrincipal User that can be accessed directly in the _Layout page. So I wrote an extension method that makes a call on my UnitOfWork and looks like this: public static UserProfile GetUserProfile(this IPrincipal u) { IUnitOfWork uow = new UnitOfWork(); return uow.UserRepository

Single App consuming multiple IoC registries and has conflicts

筅森魡賤 提交于 2019-12-13 01:42:40
问题 I have a single application that talks to separate databases through two individual UnitOfWork classes. I am using StructureMap to build my classes. Individually, each one builds and runs correctly. However, once I consume both container registries within my " Web Application ", I get conflicts. Both registries reference the same DbContext (base) class from their common framework. However, each registry has its own concrete DbContext class (that inherits from DbContext ). The problem is...

StructureMap GetAllInstances on Open Generic Types

↘锁芯ラ 提交于 2019-12-13 00:26:52
问题 I'm new to StructureMap and trying out a simple scenario I scan for all assemblies in the base folder and look for types implementing my open generic interface. Scan( scan => { scan.AssembliesFromApplicationBaseDirectory(); scan.AddAllTypesOf(typeof(IHandler<>)); }); This works and I can see it registering all such types, but when it comes to getting a list of all types I am facing issues where below statement returns null. var list = container.GetAllInstances(typeof(IHandler<>)); However, I

StructureMap 2.6.1, an IRepository<T> and a EFRepository<T,TContext>

柔情痞子 提交于 2019-12-12 11:50:12
问题 So I thought I'd be slick and try this. I need to pass around a context without newing it up every time AND be able to define the mappings (Entity framework) -- in order to do this I need to inherit then override the DbContext class. I'd like to keep it plugable with any context I toss in so that's what led me to this. I got a IRepository interface that takes a (entity) with your usual suspects in it, and an implementation of it with a dependency on IContextFactory ... public interface

Decorating a generic interface with Structuremap

百般思念 提交于 2019-12-12 11:13:58
问题 I have a generic interface, that takes in two generic types. I want to decorate all versions returned, but since I don't know the type when calling EnrichWith, it obviously doesn't compile. I've tried using the EnrichWith overload that passes in the context, thinking maybe I could grab the generic types passed in and call Activator.CreateInstance, but the context doesn't have any useful information on it when debugging and inspecting it. Here's what I have so far. This is my generic interface

Creating plugin scanner with StructureMap

让人想犯罪 __ 提交于 2019-12-12 09:59:46
问题 I'm attempting to write a StructureMap plugin scanner for Payment Gateway implementations. I have created an IPaymentGateway interface in an external library. I have created several implementations of IPaymentGateway and put those .dlls in my C:\Extensions\ folder. Here is my StructureMap configuration: ObjectFactory.Initialize(cfg => { cfg.Scan(scanner => { scanner.AssembliesFromPath(@"C:\Extensions\"); }); }); Here is my calling code: var list = ObjectFactory.GetAllInstances<IPaymentGateway

StructureMap and scanning assemblies

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 08:38:42
问题 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

StructureMap - DI - Multiple Concrete Implementation

[亡魂溺海] 提交于 2019-12-12 03:07:03
问题 I have referred multiple threads for solution but those did not help :( Any help to provide solution in terms of code on below problem is appreciated class Program { static void Main(string[] args) { //StructureMapConfiguration(); var registry = new Registry(); registry.IncludeRegistry<DependencyRegistry>(); var container = new Container(registry); var depend = container.GetInstance<ITest>(); var controller1 = new Controller1(depend); controller1.M1(); var controller2 = new Controller2(depend

which one is better structure map or unity application block

不想你离开。 提交于 2019-12-12 02:55:54
问题 I want to use dependancy injection technique in my site. For that i want to choose either structuremap or unity application block. So which one is better and why we should use one of them? 回答1: There's a whole discussion on the two in this question. 来源: https://stackoverflow.com/questions/1398486/which-one-is-better-structure-map-or-unity-application-block