本文整理汇总了C#中ITypeFinder.FindClassesOfType方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeFinder.FindClassesOfType方法的具体用法?C# ITypeFinder.FindClassesOfType怎么用?C# ITypeFinder.FindClassesOfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeFinder
的用法示例。
在下文中一共展示了ITypeFinder.FindClassesOfType方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Register
public void Register(Autofac.ContainerBuilder builder, ITypeFinder typeFinder)
{
builder.RegisterType<WorkflowEngine>().As<IWorkflowEngine>().InstancePerHttpRequest();
builder.RegisterAssemblyTypes(typeFinder.GetAssemblies().ToArray())
.AssignableTo<IAutoActivityHandler>()
.AsImplementedInterfaces();
Assembly[] assemblies = typeFinder.GetAssemblies().ToArray();
builder.RegisterAssemblyTypes(assemblies)
.AssignableTo<IAutoActivityHandler>()
.AsImplementedInterfaces();
//regisger [UUID("ApplyQuota-2.0-Approve-ActivityExecutedEvent")]
var handlers = typeFinder.FindClassesOfType(typeof(IAutoActivityHandler)).ToList();
foreach (var handler in handlers)
{
object[] attrs = handler.GetCustomAttributes(typeof(UUIDAttribute), false);
string uuid = string.Empty;
if (attrs != null)
{
foreach (UUIDAttribute attr in attrs)
{
uuid = attr.UUID;
}
builder.RegisterType(handler).As<IAutoActivityHandler>().Keyed<IAutoActivityHandler>(uuid)
.InstancePerHttpRequest();
}
}
//regisger [UUID("ApplyQuota-2.0-Approve-ActivityExecutedEvent")]
var consumers = typeFinder.FindClassesOfType(typeof(IConsumer<>)).ToList();
foreach (var consumer in consumers)
{
object[] attrs = consumer.GetCustomAttributes(typeof(UUIDAttribute), false);
string uuid = string.Empty;
if (attrs != null)
{
foreach (UUIDAttribute attr in attrs)
{
uuid = attr.UUID;
}
var interfaceType = consumer.FindInterfaces((type, criteria) =>
{
var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
return isMatch;
}, typeof(IConsumer<>))[0];
builder.RegisterType(consumer).As(interfaceType)
.Keyed(uuid, interfaceType)
.InstancePerHttpRequest();
}
}
}
示例2: Register
public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
{
Singleton<IDependencyResolver>.Instance = new DependencyResolver();
string collectionString = "Data Source=.;Initial Catalog=demo;User ID=sa;Password=sa;Trusted_Connection=False;";
builder.Register<IDbContext>(c => new WaterMoonContext(collectionString)).PerLifeStyle(ComponentLifeStyle.LifetimeScope);
builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)).PerLifeStyle(ComponentLifeStyle.LifetimeScope);
builder.RegisterGeneric(typeof(PagedList<>)).As(typeof(IPagedList<>)).PerLifeStyle(ComponentLifeStyle.LifetimeScope);
builder.RegisterType<DefualtMapping>().As<IMapping>().SingleInstance();
//注册所有实现IConsumer<>类型的对象
var consumers = typeFinder.FindClassesOfType(typeof(IConsumer<>)).ToList();
foreach (var consumer in consumers)
{
builder.RegisterType(consumer)
.As(consumer.FindInterfaces((type, criteria) =>
{
var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
return isMatch;
}, typeof(IConsumer<>)))
.PerLifeStyle(ComponentLifeStyle.LifetimeScope);
}
builder.RegisterType<EventPublisher>().As<IEventPublisher>().SingleInstance();
builder.RegisterType<SubscriptionService>().As<ISubscriptionService>().SingleInstance();
builder.RegisterType<DemoService>().As<IDemoService>().PerLifeStyle(ComponentLifeStyle.LifetimeScope);
}
示例3: Register
public void Register(ContainerBuilder builder, ITypeFinder typeFinder)
{
//HTTP context and other related stuff
builder.Register(c =>
//register FakeHttpContext when HttpContext is not available
HttpContext.Current != null ?
(new HttpContextWrapper(HttpContext.Current) as HttpContextBase) :
(new FakeHttpContext("~/") as HttpContextBase))
.As<HttpContextBase>()
.InstancePerHttpRequest();
builder.Register(c => c.Resolve<HttpContextBase>().Request)
.As<HttpRequestBase>()
.InstancePerHttpRequest();
builder.Register(c => c.Resolve<HttpContextBase>().Response)
.As<HttpResponseBase>()
.InstancePerHttpRequest();
builder.Register(c => c.Resolve<HttpContextBase>().Server)
.As<HttpServerUtilityBase>()
.InstancePerHttpRequest();
builder.Register(c => c.Resolve<HttpContextBase>().Session)
.As<HttpSessionStateBase>()
.InstancePerHttpRequest();
builder.RegisterType<SqlServerProvider>().As<IDbProvider>();
builder.RegisterType<MemoryProvider>().Named<ICache>("memory");
var list = typeFinder.FindClassesOfType<ICache>().ToList();
list.ForEach(s=>builder.RegisterType(s));
//list.ForEach(s=>builder.RegisterType<s>());
}
示例4: RegisterDependencies
public void RegisterDependencies(ContainerBuilder builder, ITypeFinder typeFinder)
{
var consumers = typeFinder.FindClassesOfType<IExamineEventsConsumer>(true);
foreach (var consumer in consumers)
{
builder.RegisterType(consumer).As<IExamineEventsConsumer>().SingleInstance();
}
}
示例5: RegisterDependencies
public void RegisterDependencies(ContainerBuilder builder, ITypeFinder typeFinder)
{
var types = typeof(IConsumer<>);
var consumers = typeFinder.FindClassesOfType(types);
foreach (var consumer in consumers)
{
builder.RegisterType(consumer)
.As(consumer.FindInterfaces((type, criteria) =>
type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition())
, typeof(IConsumer<>)))
.InstancePerRequest();
}
}
示例6: Register
public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
{
var contextList = typeFinder.FindClassesOfType<BaseDbContext>(true);
foreach (var type in contextList)
{
var dbname = type.Name.Replace("Entities","");
if (ConfigurationManager.ConnectionStrings[dbname] == null)
{
continue;
}
RegisterDB(builder, type, typeFinder);
}
//cache manager
builder.RegisterType<CacheManager>().As<ICacheManager>().Named<ICacheManager>("sdf_cache_static").SingleInstance();
var services = typeFinder.FindClassesOfType<BaseService>().ToList();
services.ForEach(s => builder.RegisterType(s).AsImplementedInterfaces().PropertiesAutowired());
builder.RegisterType<AccountService>().As<IAccount>();
}
示例7: RegisterDB
private void RegisterDB(ContainerBuilder builder, Type type, ITypeFinder typeFinder)
{
var entityAssembly = Assembly.Load(type.Namespace);
builder.RegisterType(type).Named<DbContext>(type.FullName);
var a = new Assembly[] {entityAssembly};
var typeList = typeFinder.FindClassesOfType<BaseEntity>(a,true);
var tRepository = typeof(EfRepository<>);
foreach (Type t in typeList)
{
var t2 = tRepository.MakeGenericType(t);
builder.RegisterType(t2).AsImplementedInterfaces().WithParameter(ResolvedParameter.ForNamed<DbContext>(type.FullName));
}
}
示例8: CreateEngineInstance
/// <summary>
/// Creates a factory instance and adds a http application injecting facility.
/// </summary>
/// <returns>A new factory</returns>
public static IEngine CreateEngineInstance(ITypeFinder typeFinder)
{
var engines = typeFinder.FindClassesOfType<IEngine>().ToArray();
engines = engines.Where(it => it != typeof(MEF.MEFEngine)).ToArray();
if (engines.Length > 0)
{
var defaultEngine = (IEngine)Activator.CreateInstance(engines[0], typeFinder);
return defaultEngine;
}
else
{
return new MEF.MEFEngine(typeFinder);
}
}
示例9: MapGeneric
protected void MapGeneric(ContainerBuilder builder, ITypeFinder typeFinder, Type mapperType,
IEnumerable<Type> contentTypes, Type defaultMapperType)
{
var allConverterTypes = typeFinder.FindClassesOfType(mapperType).ToArray();
foreach (var contentType in contentTypes)
{
var specificMapperType = allConverterTypes.FirstOrDefault(ct =>
{
var t = ct.GetInterfaces().First(i => i.IsGenericType && i.GetGenericTypeDefinition() == mapperType);
return t.GenericTypeArguments[0] == contentType;
});
var concreteType = specificMapperType ?? defaultMapperType.MakeGenericType(contentType);
var target = mapperType.MakeGenericType(contentType);
builder.RegisterType(concreteType).As(target).InstancePerRequest();
}
}
示例10: Register
//.........这里部分代码省略.........
builder.RegisterType<PictureService>().As<IPictureService>().InstancePerLifetimeScope();
builder.RegisterType<MessageTemplateService>().As<IMessageTemplateService>().InstancePerLifetimeScope();
builder.RegisterType<QueuedEmailService>().As<IQueuedEmailService>().InstancePerLifetimeScope();
builder.RegisterType<NewsLetterSubscriptionService>().As<INewsLetterSubscriptionService>().InstancePerLifetimeScope();
builder.RegisterType<CampaignService>().As<ICampaignService>().InstancePerLifetimeScope();
builder.RegisterType<EmailAccountService>().As<IEmailAccountService>().InstancePerLifetimeScope();
builder.RegisterType<WorkflowMessageService>().As<IWorkflowMessageService>().InstancePerLifetimeScope();
builder.RegisterType<MessageTokenProvider>().As<IMessageTokenProvider>().InstancePerLifetimeScope();
builder.RegisterType<Tokenizer>().As<ITokenizer>().InstancePerLifetimeScope();
builder.RegisterType<EmailSender>().As<IEmailSender>().InstancePerLifetimeScope();
builder.RegisterType<CheckoutAttributeFormatter>().As<ICheckoutAttributeFormatter>().InstancePerLifetimeScope();
builder.RegisterType<CheckoutAttributeParser>().As<ICheckoutAttributeParser>().InstancePerLifetimeScope();
builder.RegisterType<CheckoutAttributeService>().As<ICheckoutAttributeService>().InstancePerLifetimeScope();
builder.RegisterType<GiftCardService>().As<IGiftCardService>().InstancePerLifetimeScope();
builder.RegisterType<OrderService>().As<IOrderService>().InstancePerLifetimeScope();
builder.RegisterType<OrderReportService>().As<IOrderReportService>().InstancePerLifetimeScope();
builder.RegisterType<OrderProcessingService>().As<IOrderProcessingService>().InstancePerLifetimeScope();
builder.RegisterType<OrderTotalCalculationService>().As<IOrderTotalCalculationService>().InstancePerLifetimeScope();
builder.RegisterType<ShoppingCartService>().As<IShoppingCartService>().InstancePerLifetimeScope();
builder.RegisterType<PaymentService>().As<IPaymentService>().InstancePerLifetimeScope();
builder.RegisterType<EncryptionService>().As<IEncryptionService>().InstancePerLifetimeScope();
builder.RegisterType<FormsAuthenticationService>().As<IAuthenticationService>().InstancePerLifetimeScope();
//pass MemoryCacheManager as cacheManager (cache settings between requests)
builder.RegisterType<UrlRecordService>().As<IUrlRecordService>()
.WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
.InstancePerLifetimeScope();
builder.RegisterType<ShipmentService>().As<IShipmentService>().InstancePerLifetimeScope();
builder.RegisterType<ShippingService>().As<IShippingService>().InstancePerLifetimeScope();
builder.RegisterType<TaxCategoryService>().As<ITaxCategoryService>().InstancePerLifetimeScope();
builder.RegisterType<TaxService>().As<ITaxService>().InstancePerLifetimeScope();
builder.RegisterType<TaxCategoryService>().As<ITaxCategoryService>().InstancePerLifetimeScope();
//pass MemoryCacheManager as cacheManager (cache settings between requests)
builder.RegisterType<CustomerActivityService>().As<ICustomerActivityService>()
.WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
.InstancePerLifetimeScope();
if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["UseFastInstallationService"]) &&
Convert.ToBoolean(ConfigurationManager.AppSettings["UseFastInstallationService"]))
{
builder.RegisterType<SqlFileInstallationService>().As<IInstallationService>().InstancePerLifetimeScope();
}
else
{
builder.RegisterType<CodeFirstInstallationService>().As<IInstallationService>().InstancePerLifetimeScope();
}
builder.RegisterType<ForumService>().As<IForumService>().InstancePerLifetimeScope();
builder.RegisterType<PollService>().As<IPollService>().InstancePerLifetimeScope();
builder.RegisterType<BlogService>().As<IBlogService>().InstancePerLifetimeScope();
builder.RegisterType<WidgetService>().As<IWidgetService>().InstancePerLifetimeScope();
builder.RegisterType<TopicService>().As<ITopicService>().InstancePerLifetimeScope();
builder.RegisterType<NewsService>().As<INewsService>().InstancePerLifetimeScope();
builder.RegisterType<DateTimeHelper>().As<IDateTimeHelper>().InstancePerLifetimeScope();
builder.RegisterType<SitemapGenerator>().As<ISitemapGenerator>().InstancePerLifetimeScope();
builder.RegisterType<PageHeadBuilder>().As<IPageHeadBuilder>().InstancePerLifetimeScope();
builder.RegisterType<ScheduleTaskService>().As<IScheduleTaskService>().InstancePerLifetimeScope();
builder.RegisterType<ExportManager>().As<IExportManager>().InstancePerLifetimeScope();
builder.RegisterType<ImportManager>().As<IImportManager>().InstancePerLifetimeScope();
builder.RegisterType<PdfService>().As<IPdfService>().InstancePerLifetimeScope();
builder.RegisterType<ThemeProvider>().As<IThemeProvider>().InstancePerLifetimeScope();
builder.RegisterType<ThemeContext>().As<IThemeContext>().InstancePerLifetimeScope();
builder.RegisterType<ExternalAuthorizer>().As<IExternalAuthorizer>().InstancePerLifetimeScope();
builder.RegisterType<OpenAuthenticationService>().As<IOpenAuthenticationService>().InstancePerLifetimeScope();
builder.RegisterType<RoutePublisher>().As<IRoutePublisher>().SingleInstance();
//Register event consumers
var consumers = typeFinder.FindClassesOfType(typeof(IConsumer<>)).ToList();
foreach (var consumer in consumers)
{
builder.RegisterType(consumer)
.As(consumer.FindInterfaces((type, criteria) =>
{
var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
return isMatch;
}, typeof(IConsumer<>)))
.InstancePerLifetimeScope();
}
builder.RegisterType<EventPublisher>().As<IEventPublisher>().SingleInstance();
builder.RegisterType<SubscriptionService>().As<ISubscriptionService>().SingleInstance();
//Anko.Plugins.Admin.Uploader
builder.RegisterType<ProductUploader>().As<IProductUploader>();
builder.RegisterType<ProductValidator>().As<IProductValidator>();
builder.RegisterType<ConsoleLogger>().As<ILogger>().InstancePerLifetimeScope();
builder.RegisterType<ProductResolver>().As<IProductResolver>().InstancePerLifetimeScope();
}
示例11: Register
public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
{
//HTTP context and other related stuff
builder.Register(c =>
//register FakeHttpContext when HttpContext is not available
HttpContext.Current != null ?
(new HttpContextWrapper(HttpContext.Current) as HttpContextBase) :
(new FakeHttpContext("~/") as HttpContextBase))
.As<HttpContextBase>()
.InstancePerLifetimeScope();
builder.Register(c => c.Resolve<HttpContextBase>().Request)
.As<HttpRequestBase>()
.InstancePerLifetimeScope();
builder.Register(c => c.Resolve<HttpContextBase>().Response)
.As<HttpResponseBase>()
.InstancePerLifetimeScope();
builder.Register(c => c.Resolve<HttpContextBase>().Server)
.As<HttpServerUtilityBase>()
.InstancePerLifetimeScope();
builder.Register(c => c.Resolve<HttpContextBase>().Session)
.As<HttpSessionStateBase>()
.InstancePerLifetimeScope();
//web helper
builder.RegisterType<WebHelper>().As<IWebHelper>().InstancePerLifetimeScope();
//data layer
var dataSettingsManager = new DataSettingsManager();
var dataProviderSettings = dataSettingsManager.LoadSettings();
builder.Register(c => dataSettingsManager.LoadSettings()).As<DataSettings>();
builder.Register(x => new EfDataProviderManager(x.Resolve<DataSettings>())).As<BaseDataProviderManager>().InstancePerDependency();
builder.Register(x => x.Resolve<BaseDataProviderManager>().LoadDataProvider()).As<IDataProvider>().InstancePerDependency();
if (dataProviderSettings != null && dataProviderSettings.IsValid())
{
var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
var dataProvider = efDataProviderManager.LoadDataProvider();
dataProvider.InitConnectionFactory();
var datacontext = new AFObjectContext(dataProviderSettings.DataConnectionString);
datacontext.Database.Log = s => Debug.Print(s);
Database.SetInitializer<AFObjectContext>(null);
builder.Register<IDbContext>(c => datacontext)
.InstancePerLifetimeScope();
}
else
{
var datacontext = new AFObjectContext(dataSettingsManager.LoadSettings().DataConnectionString);
datacontext.Database.Log = s => Debug.Print(s);
Database.SetInitializer<AFObjectContext>(null);
builder.Register<IDbContext>(
c => datacontext)
.InstancePerLifetimeScope();
}
builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope();
//cache manager
builder.RegisterType<MemoryCacheManager>().As<ICacheManager>().Named<ICacheManager>("af_cache_static").SingleInstance();
builder.RegisterType<PerRequestCacheManager>().As<ICacheManager>().Named<ICacheManager>("af_cache_per_request").InstancePerLifetimeScope();
builder.RegisterType<CustomerService>().As<ICustomerService>().InstancePerLifetimeScope();
builder.RegisterType<ScheduleTaskService>().As<IScheduleTaskService>().InstancePerLifetimeScope();
builder.RegisterType<FormsAuthenticationService>().As<IAuthenticationService>().InstancePerLifetimeScope();
builder.RegisterType<CustomerRegistrationService>().As<ICustomerRegistrationService>().InstancePerLifetimeScope();
builder.RegisterType<EncryptionService>().As<IEncryptionService>().InstancePerLifetimeScope();
builder.RegisterType<GenericAttributeService>().As<IGenericAttributeService>().InstancePerLifetimeScope();
builder.RegisterType<SettingService>().As<ISettingService>().InstancePerLifetimeScope();
builder.RegisterType<DefaultLogger>().As<ILogger>().InstancePerLifetimeScope();
builder.RegisterType<OrderProcessingService>().As<IOrderProcessingService>().InstancePerLifetimeScope();
builder.RegisterType<OrderService>().As<IOrderService>().InstancePerLifetimeScope();
//Register event consumers
var consumers = typeFinder.FindClassesOfType(typeof(IConsumer<>)).ToList();
foreach (var consumer in consumers)
{
builder.RegisterType(consumer)
.As(consumer.FindInterfaces((type, criteria) =>
{
var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
return isMatch;
}, typeof(IConsumer<>)))
.InstancePerLifetimeScope();
}
builder.RegisterType<EventPublisher>().As<IEventPublisher>().SingleInstance();
builder.RegisterType<SubscriptionService>().As<ISubscriptionService>().SingleInstance();
}