unity-container

Unable to register DbConnection with Unity and Entity Framework

不羁的心 提交于 2020-01-25 01:07:10
问题 I am not at all sure what the underlying problem is that is causing this exception. I am using ASP.NET MVC, with Unity.Mvc, and Entity Framework 6. I have the following code to register my repositories: public static void RegisterTypes(IUnityContainer container) { // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements. // container.LoadConfiguration(); // TODO: Register your types here // container

Prism with Xamarin for Android - InvalidOperationException on Launch

人盡茶涼 提交于 2020-01-24 21:21:06
问题 I'm new to Xamarin and Prism, so forgive me if I'm missing something obvious. I am following the example of this project in GitHub. However, I am getting the following error when running my Android project. System.InvalidOperationException: The current type, MyApp.Abstractions.IFacebookManager, is an interface and cannot be constructed. Are you missing a type mapping? The error is occurring in EntryPage.xaml.g.cs in the LoadFromXaml() method. [global::Xamarin.Forms.Xaml.XamlFilePathAttribute(

Unity - How to pass null in the constructor parameter for nullable int

北战南征 提交于 2020-01-24 10:03:45
问题 I have a class that takes nullable int as parameter. public class Test { public Test(int? p) { // ...... } // ...... } How do I resolve it using unity (passing null as parameter)? myContainer.RegisterType<Test>(new InjectionConstructor(10)); This works passing 10 as value, but if I pass null, it throws exception. 回答1: Edited to use generics: Try to use InjectionParameter instead: container.RegisterType<Test>(new InjectionConstructor(new InjectionParameter<int?>(null))); 回答2: Use an

Entity Framework Code First can't find database in server explorer

◇◆丶佛笑我妖孽 提交于 2020-01-24 03:26:08
问题 So I was following this introduction to the Entity Framework Code First to create a new database ( https://msdn.microsoft.com/en-us/data/jj193542 ) and I followed the example completely. Now I want to add it to my server explorer in Visual Studio 2013. Tried both LocalDb ((localdb)\v11.0) or SQL Express (.\SQLEXPRESS) but the database doesn't show, I know it's working because I've tested it multiple times now and it keeps appending and fetching data from the database, so where would it be

How to load unity settings from config file?

我与影子孤独终老i 提交于 2020-01-23 19:23:19
问题 I have an unity configuration file( App.config ) as below: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Unity.Configuration"/> </configSections> <unity xmlns="http://schemas.microsoft.com/practices/2010/unity"> <alias alias="IProductService" type="UnityExample.Service.IProductService, UnityExample.Service" /> <containers> <container name="Service"> <register type=

Unity: Register two interfaces as one singleton with interception

老子叫甜甜 提交于 2020-01-22 20:28:06
问题 I have a class that implements two interfaces, and I want to apply interception to the class's methods. I'm following the advice in Unity Register two interfaces as one singleton, but I'm surprised by the results. In a nutshell, it seems that my CallHandler is called twice. The shortest example I have is this: public interface I1 { void Method1(); } public interface I2 { void Method2(); } public class C : I1, I2 { [Log] public void Method1() {} public void Method2() {} } public class

Inject require object depends on condition in constructor injection

╄→гoц情女王★ 提交于 2020-01-21 09:53:30
问题 I have an interface public interface ITrnsitReport { List<UserDefinedType> GetTransitReportData (); } And it has only one implementation which is public class TransitReport : ITrnsitReport { private IValidateInput _inputValidation = null; private readonly ITransitRepository _transitRepo = null; public TransitReport (IValidateInput inputValidation, ITransitRepository transitRepo) { _inputValidation = inputValidation; _transitRepo = transitRepo; } public List<UserDefinedType>

Resolve named registration dependency in Unity with runtime parameter

╄→尐↘猪︶ㄣ 提交于 2020-01-17 10:20:47
问题 I have a following problem. I register my components and initialize them in Unity like this (example is for a Console application): public class SharePointBootstrapper : UnityBootstrapper { ... public object Initialize(Type type, object parameter) => Container.Resolve(type, new DependencyOverride<IClientContext>(Container.Resolve<IClientContext>(parameter.ToString())), new DependencyOverride<ITenantRepository>(Container.Resolve<ITenantRepository>(parameter.ToString()))); public void

Resolve named registration dependency in Unity with runtime parameter

我怕爱的太早我们不能终老 提交于 2020-01-17 10:20:26
问题 I have a following problem. I register my components and initialize them in Unity like this (example is for a Console application): public class SharePointBootstrapper : UnityBootstrapper { ... public object Initialize(Type type, object parameter) => Container.Resolve(type, new DependencyOverride<IClientContext>(Container.Resolve<IClientContext>(parameter.ToString())), new DependencyOverride<ITenantRepository>(Container.Resolve<ITenantRepository>(parameter.ToString()))); public void

Injecting new constructor parameters every time a type is resolved using unity

不打扰是莪最后的温柔 提交于 2020-01-17 06:58:28
问题 I've just come across an issue recently where I want new types injected into the requested type every time it is resolved. The current code I have to register the type is container.RegisterType<IFirstT, FirstT>(); container.RegisterType<ISecondT, SecondT>(); container.RegisterType<IInjectableT, InjectableT>() .Configure<InjectedMembers>() .ConfigureInjectionFor<InjectableT>( new InjectionConstructor( container.Resolve<IFirstT>(), container.Resolve<ISecondT>(), ) ); I've now come to realise