泛型中的依赖注入 [英] Dependency injection in generics

查看:87
本文介绍了泛型中的依赖注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问我是否可以这样做:



I ask about if i can do something like that:

//In classlib1.dll
class Context : IdentityDbContext<IdentityUser> 
{
    .............
}

//In classlib2.dll
class MyUser : IdentityUser
{
   extend IdentityUser.......
}





依赖注入注册:

= >当您找到IdentityUser时,请使用MyUser



Dependency injection registration:
=> When you find "IdentityUser" use "MyUser"

推荐答案

请参阅我对该问题的评论。由于你的帖子没有提出真正的问题,没有什么可以回答的。



但是,我可以给你一些提示。首先,您是否注意到内容类是非通用的?为什么?其次,这里是如何抽象派生类:

Please see my comment to the question. As your post does not make a real question, there is nothing to answer to.

However, I can give you a couple of hints. First, did you pay attention that you Content class is non-generic? Why? Secondly, here is how the derived classes are abstracted:
class SomethingGeneric<IDENTITY>
    where IDENTITY : IdentityUser
{
    // ...
}



或者说,


or, say,

class IdentityDbContext<t> { /* ... */ }

class SomethingGeneric<IDENTITY> : IdentityDbContext<IDENTITY>
    where IDENTITY : IdentityUser
{
    // ...
}





免责声明这些只是一些提示;他们可能与这个问题无关。这个问题没有真正制定。



有问题吗?



-SA


这篇关于泛型中的依赖注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆