ABP 原始碼分析彙總之 AutoMapper

2022-01-28 13:35:12 字數 2592 閱讀 9355

安裝時只需要安裝 如下即可:

findandautomaptypes方法中_typefinder.find(),看名字就知道是根據裡面的條件,找到符合條件的型別。看一下原始碼,它是如何找的,

public

typefinder是介面,那它預設實現就是typefinder,我們在原始碼中很快找到了它:

public

class

typefinder : itypefinder

public type find(funcbool>predicate)

private

type getalltypes()}}

return

_types;

}private listcreatetypelist()

catch

(reflectiontypeloadexception ex)

if(typesinthisassembly.isnullorempty())

alltypes.addrange(typesinthisassembly.where(type => type != null

)); }

catch

(exception ex)

}return

alltypes;}}

可以看到_assemblyfinder.getallassemblies().distinct();

通過_assemblyfinder 是介面iassemblyfinder,那它的實現是誰呢,看下面的**。 這裡是castle windsor實現註冊的方式之一。

internal

class

abpcoreinstaller : iwindsorinstaller

}

我們看到abpassemblyfinder是我們要找到的類。

public

class

abpassemblyfinder : iassemblyfinder

public listgetallassemblies()

return

assemblies.distinct().tolist();}}

看到這裡就可以知道,abp是通過module來找到assemblies的。 我們可以 abpmodulemanager : iabpmodulemanager這個類得到所有的模組。

再來看來這裡的過濾條件:

var types = _typefinder.find(type =>

);

三個attribute. automapattribute, automapfromattribute, automaptoattribute,通過名稱可以知道它們的用途。

此外,abp還給我們提供了乙個有用的擴充套件automapextensions,使用起來更加方便

public

static

class

automapextensions

//////

///

/// ///

source type

///destination type

///source object

///destination object

///public

static tdestination mapto(this

tsource source, tdestination destination)

}

原始碼分析彙總

storm 簡介 storm topology的併發度 storm guaranteeing message processing storm transactional topologies twitter storm drpc storm 多語言支援 storm starter overview...

ABP原始碼分析 服務配置 1

比較隨意,記錄下過程,以便忘了以後重拾。program.cs internal static ihostbuilder createhostbuilder string args host.createdefaultbuilder args configurewebhostdefaults webb...

Storm 原始碼分析彙總

storm 簡介 storm topology的併發度 storm guaranteeing message processing storm transactional topologies twitter storm drpc storm 多語言支援 storm starter overview...