I tried to use autofac IRegistrationSource resolve other interface,but it's not working. Below is my code:
public class SettingsSource : IRegistrationSource { static readonly MethodInfo BuildMethod = typeof(SettingsSource).GetMethod( "BuildRegistration", BindingFlags.Static | BindingFlags.NonPublic);
public IEnumerable<IComponentRegistration> RegistrationsFor(
Service service,
Func<Service, IEnumerable<IComponentRegistration>> registrations)
{
var ts = service as TypedService;
if (ts != null && typeof(ISettings).IsAssignableFrom(ts.ServiceType))
{
var buildMethod = BuildMethod.MakeGenericMethod(ts.ServiceType);
yield return (IComponentRegistration)buildMethod.Invoke(null, null);
}
}
static IComponentRegistration BuildRegistration<TSettings>()
where TSettings : ISettings, new()
{
return RegistrationBuilder
.ForDelegate((c, p) =>
{
return c.Resolve<ISettingService>().LoadSetting<TSettings>();
})
.InstancePerLifetimeScope()
.CreateRegistration();
}
public bool IsAdapterForIndividualComponents { get { return false; } }
}
method BuildRegistration can't be fired.
I checked bellow links, still can't figure out why. Autofac. How to use custom method(property) to resolve some interface?
anyone can give a clue?
Thanks
Aucun commentaire:
Enregistrer un commentaire