FreshMvvm
FreshMvvm copied to clipboard
IoC Generic type not working #270
@rid00z
Please check this issue is closed without understanding:
https://github.com/rid00z/FreshMvvm/issues/270
@moreirawebmaster : Okay, I understood the issue. Have u tried the workaround as mentioned in the URL you have shared? https://stackoverflow.com/questions/15450518/how-to-register-a-generic-interface-using-tinyioc . If that does not work for you, probably we will need to update the version of TinyIOC in our project. Will look into it soon
@libin85 In FreshIoC not accept generic types:
FreshIoC.Register(typeof(IRepository<>), typeof(AzureRepository<>));
I meant has anyone tried this : container.Register(typeof(IRepository<>), typeof(AzureRepository<>)).AsMultiInstance();
I will give it a try when I get some time.
Hello,
I can't get the generics to work even using the workaround discussed for TinyIoc.
The workaround below results in the second parameter not being allowed as string (doesn't seem to be implementation for register with string,string
container.Register(typeof(IRepository<>), typeof(AzureRepository<>)).AsMultiInstance();
Do you have any recommendations? I can't find any other solutions. Thanks.Brent
Will this be fixed in an upcoming version? Will there be a new version to FreshMVVM in the near feature at all? Or should we look further to an actively maintained package?
I wanted to use this for the generic logging framework from Microsoft. I found a solution, it skips the IFreshIOC
interface and goes directly to the underlying container.
var loggerFactory = LoggerFactory.Create(); // Omitted the configuration
FreshIOC.Container.Register<ILoggerFactory>(loggerFactory);
var defaultLogger = loggerFactory.CreateLogger("Default");
FreshIOC.Container.Register<ILogger>(defaultLogger);
// In TinyIOC it works this way: container.Register(typeof(ILogger<>), typeof(Logger<>)).AsMultiInstance();
// Due to the abstraction FreshMVVM applyed we cannot use that, but we can get to the underlying container the following:
FreshTinyIOCBuiltIn.Current.Register(typeof(ILogger<>), typeof(Logger<>)).AsMultiInstance();
Credits to https://johan.driessen.se/posts/Resolving-ILogger-with-Nancy-and-TinyIoC/ for resolving ILogger with TinyIoC.