Registration using modules
Registration using modules allows more flexibility, reduced complexity, allows configuration parameters to be explicit and better abstraction and type safety.
To use module you have to create a class, which inherits from Autofac.Module and overrides the Load method, fx.:
class ModuleReg : Module
{
protected override void Load(ContainerBuilder builder)
{
base.Load(builder);
builder.RegisterType<object>();
}
}
To register a module the following are done:var builder = new ContainerBuilder();
builder.RegisterModule(new ModuleReg());
var container = builder.Build();
Now you can get all instances, types and everything else registered in the module, resolved just as normal. Modules can register anything you can outside a module, for example you can register more modules.Modules can are more dynamic as you can set properties and such to indicate different scenarios. More information about module registration can be found here
Autofac events
There are a couple for events which can be handled. These event as described below.
- Preparing
- Fired before the activation process to allow parameters to be changed or an alternative instance to be provided.
- Activating
- Fires after the construction of an instance but before it is shared with any other or any members invoked on it.
- Activated
- Fire when the activation process for a new instance is complete.
- Registered
- Information about the occurrence of a component being registered with a container.
builder.RegisterType<object>().OnPreparing(somedelegate);
builder.RegisterType<object>().OnActivated(somedelegate);
builder.RegisterType<object>().OnActivating(somedelegate);
builder.RegisterType<object>().OnRegistered(somedelegate);
Multiple events can be handled like this:builder.RegisterType<object>().OnPreparing(somedelegate)
.OnActivated(somedelegate);
These events are poorly documented, so here is a quick intro. The OnPreparing method, takes this parameter:Action<PreparingEventArgs>
And you can changed the instance parameters like this:IEnumerable<Parameter> parameters = new Parameter[] { new NamedParameter("n", 1) }; builder.RegisterType<object>().OnPreparing(e => e.Parameters = parameters);The OnActivating method take this parameter:
Action<IActivatingEventArgs<TLimit>>And you can change the instance provided like this:
builder.RegisterType<object>().OnActivation(e => e.ReplaceInstance(new object());
The OnActivated method take this parameter:Action<IActivatedEventArgs<TLimit>>
And you can use the instance provided like this:builder.RegisterType<object>().OnActivated(e => e.Instance.Method());And at last the OnRegistered method, which takes this parameters:
Action<ComponentRegisteredEventArgs>
In my opinion this event aren't very useful, but it is still included here for completeness. You can only get the ComponentRegistry and the ComponentRegistration from this event.builder.RegisterType<object>().OnRegistered(e =>
{
registry = e.ComponentRegistry;
cr = e.ComponentRegistration;
});
Great series, very helpful, thank you.
ReplyDeleteVery helpful. Thanks
ReplyDeletehttps://bayanlarsitesi.com/
ReplyDeleteGöktürk
Yenidoğan
Şemsipaşa
Çağlayan
PLİQ3
Denizli
ReplyDeleteAnkara
Antep
Bursa
Eskişehir
8İK10
görüntülü show
ReplyDeleteücretlishow
PUO
görüntülü show
ReplyDeleteücretlishow
NHDT
https://titandijital.com.tr/
ReplyDeleteçanakkale parça eşya taşıma
kırıkkale parça eşya taşıma
erzurum parça eşya taşıma
burdur parça eşya taşıma
OKX4
Çorlu Lojistik
ReplyDeleteManisa Lojistik
Eskişehir Lojistik
Afyon Lojistik
Konya Lojistik
0RJ
ığdır evden eve nakliyat
ReplyDeleteağrı evden eve nakliyat
maraş evden eve nakliyat
diyarbakır evden eve nakliyat
şırnak evden eve nakliyat
EPTTVY
E27AD
ReplyDeleteAdıyaman Evden Eve Nakliyat
Giresun Şehir İçi Nakliyat
Şırnak Evden Eve Nakliyat
Eskişehir Lojistik
Ankara Boya Ustası
Giresun Parça Eşya Taşıma
Antalya Parça Eşya Taşıma
Uşak Evden Eve Nakliyat
Chat Gpt Coin Hangi Borsada
D787F
ReplyDeletemasteron for sale
buy dianabol methandienone
sustanon
Referans Kimliği Nedir
Silivri Parke Ustası
buy anapolon oxymetholone
Erzincan Evden Eve Nakliyat
Sivas Evden Eve Nakliyat
deca durabolin
DA23D
ReplyDeleteMaraş Evden Eve Nakliyat
Çankaya Parke Ustası
Pursaklar Parke Ustası
Kırşehir Evden Eve Nakliyat
İstanbul Şehirler Arası Nakliyat
Aydın Evden Eve Nakliyat
Maraş Şehirler Arası Nakliyat
Antep Parça Eşya Taşıma
Diyarbakır Şehirler Arası Nakliyat
410EE
ReplyDeletereferanskodunedir.com.tr
4F0E0
ReplyDeletemardin bedava sohbet odaları
artvin mobil sohbet siteleri
muş rastgele sohbet
sohbet uygulamaları
ücretsiz görüntülü sohbet
agri sesli sohbet sitesi
canlı sohbet siteleri ücretsiz
van mobil sohbet siteleri
elazığ sesli mobil sohbet
0F5E3
ReplyDeleteücretsiz sohbet uygulaması
Samsun Random Görüntülü Sohbet
agri sohbet siteleri
kütahya görüntülü sohbet ücretsiz
Adana Canli Sohbet Bedava
Nevşehir Canli Sohbet Bedava
Tekirdağ Bedava Sohbet
Nevşehir Kadınlarla Sohbet
sesli görüntülü sohbet
E1D56
ReplyDeleteKırıkkale Sesli Sohbet Sitesi
burdur canlı sohbet siteleri ücretsiz
bingöl telefonda canlı sohbet
bursa bedava görüntülü sohbet sitesi
Muğla Bedava Görüntülü Sohbet Sitesi
Aksaray Canlı Sohbet Et
kırıkkale canlı sohbet
hatay goruntulu sohbet
osmaniye görüntülü sohbet kızlarla
TFGDXYGUFRHUY
ReplyDeleteشركة صيانة افران بالاحساء
شركة تسليك مجاري بالدمام WdKXKlKHFV
ReplyDeleteشركة تسليك مجاري بالهفوف 2c8OcU96Eo
ReplyDeleteشركة تنظيف سجاد بالجبيل g5YZOaKpTy
ReplyDeleteتسليك مجاري بالاحساء GH6YMJu4cG
ReplyDeleteشركة تنظيف خزانات fZWCxNG5So
ReplyDeleteشركة تسليك مجاري بالاحساء JxwCq6bwQh
ReplyDeleteشركة رش حشرات بالاحساء kEQihF2LJq
ReplyDeleteشركة مكافحة النمل الابيض بالدمام NKroViXT7f
ReplyDeletehttps://patineteavela.blogspot.com/2014/04/o-casamento-do-joffrey-finalmente.html?sc=1733829857582#c6394624455104781006 DWra5ZMlqc
ReplyDelete