FreshMvvm icon indicating copy to clipboard operation
FreshMvvm copied to clipboard

IoC Generic type not working #270

Open moreirawebmaster opened this issue 5 years ago • 6 comments

@rid00z

Please check this issue is closed without understanding:

https://github.com/rid00z/FreshMvvm/issues/270

moreirawebmaster avatar May 18 '19 16:05 moreirawebmaster

@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 avatar May 29 '19 09:05 libin85

@libin85 In FreshIoC not accept generic types:

FreshIoC.Register(typeof(IRepository<>), typeof(AzureRepository<>));

thiagoparabas avatar Jun 06 '19 18:06 thiagoparabas

I meant has anyone tried this : container.Register(typeof(IRepository<>), typeof(AzureRepository<>)).AsMultiInstance();

libin85 avatar Jun 06 '19 23:06 libin85

I will give it a try when I get some time.

libin85 avatar Jun 07 '19 00:06 libin85

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

tallmanBS avatar May 27 '20 23:05 tallmanBS

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.

Arie-Kanarie avatar Jan 05 '21 12:01 Arie-Kanarie