本文整理汇总了C#中Autofac.ContainerBuilder.RegisterSource方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.RegisterSource方法的具体用法?C# ContainerBuilder.RegisterSource怎么用?C# ContainerBuilder.RegisterSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Autofac.ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder.RegisterSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterAutofac
public static void RegisterAutofac()
{
var builder = new ContainerBuilder();
// Register your MVC controllers.
// If AutofacConfig's assembly doesn't reference the specific controllers assemblies, use these:
// builder.RegisterControllers(typeof(MvcApplication).Assembly);
// builder.RegisterControllers(typeof(BasePublicController).Assembly);
// builder.RegisterControllers(typeof(BaseAdminController).Assembly);
// ...
builder.RegisterControllers(BuildManager.GetReferencedAssemblies().Cast<Assembly>().ToArray());
// OPTIONAL: Register model binders that require DI.
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
// OPTIONAL: Register web abstractions like HttpContextBase.
builder.RegisterModule<AutofacWebTypesModule>();
// OPTIONAL: Enable property injection in view pages.
builder.RegisterSource(new ViewRegistrationSource());
// OPTIONAL: Enable property injection into action filters.
builder.RegisterFilterProvider();
// Register services
RegisterServices(builder);
// Set the dependency resolver to be Autofac.
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
// Integration with Hangfire
GlobalConfiguration.Configuration.UseAutofacActivator(container);
}
示例2: CreateBuilder
static ContainerBuilder CreateBuilder()
{
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
containerBuilder.RegisterSource(new AutofacMockRegistrationHandler(new MoqMockFactory()));
return containerBuilder;
}
示例3: Application_Start
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
var builder = new ContainerBuilder();
builder.RegisterModelBinderProvider();
builder.RegisterModule(new AutofacWebTypesModule());
builder.RegisterSource(new ViewRegistrationSource());
builder.RegisterControllers(Assembly.GetExecutingAssembly());
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterType<InMemoryPersonRepository>().As<IPersonRepository>();
// Use application-scoped variable to mimic in-memory database
var personDatabase = new List<Person>();
builder.Register(c => personDatabase).As<List<Person>>();
IContainer container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
ModelMetadataProviders.Current = new MetadataProvider();
}
示例4: Bootstrap
public static void Bootstrap()
{
var builder = new ContainerBuilder();
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterAssemblyTypes(typeof (IHandle<>).Assembly)
.AsImplementedInterfaces();
builder.RegisterAssemblyTypes(typeof(Denormalizer<>).Assembly)
.AsImplementedInterfaces();
//HACK
builder.RegisterInstance(new Replay.Runner().Rebuild())
.AsImplementedInterfaces()
.SingleInstance();
builder.RegisterModule<EventStoreModule>();
builder.RegisterType<SignalREventDispatcher>()
.AsImplementedInterfaces()
.SingleInstance();
builder.RegisterType<InProcessCommandProcessor>()
.AsImplementedInterfaces()
.SingleInstance();
builder.RegisterSource(new ContravariantRegistrationSource());
var container = builder.Build();
Command.UseContainer(container.BeginLifetimeScope());
Denormalizer.UseContainer(container.BeginLifetimeScope());
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}
示例5: Initialize
public static IContainer Initialize(ContainerBuilder builder)
{
// Register all controllers
builder.RegisterControllers(typeof(Startup).Assembly)
.OnActivating(e =>
{
var controller = (Controller)e.Instance;
controller.TempDataProvider = new CookieTempDataProvider();
});
// Register model binders
builder.RegisterModelBinders(typeof(Startup).Assembly);
builder.RegisterModelBinderProvider();
// Register all HTTP abstractions
builder.RegisterModule<AutofacWebTypesModule>();
//Register mapper module
builder.RegisterModule(new MappingModule());
// Allow property injection in views
builder.RegisterSource(new ViewRegistrationSource());
// Allow property injection in action filters
builder.RegisterFilterProvider();
// Register all Autofac specific IModule implementations
builder.RegisterAssemblyModules(typeof(Startup).Assembly);
return builder.Build();
}
示例6: Configure
public void Configure(IComponentRegistry componentRegistry)
{
var builder = new ContainerBuilder();
if (_atomicStorageFactory == null)
{
AtomicIsInMemory(strategyBuilder => { });
}
if (_streamingRoot == null)
{
StreamingIsInFiles(Directory.GetCurrentDirectory());
}
if (_tapeStorage == null)
{
TapeIsInMemory();
}
var core = new AtomicRegistrationCore(_atomicStorageFactory);
var source = new AtomicRegistrationSource(core);
builder.RegisterSource(source);
builder.RegisterInstance(new NuclearStorage(_atomicStorageFactory));
builder
.Register(
c => new AtomicStorageInitialization(new[] {_atomicStorageFactory}, c.Resolve<ISystemObserver>()))
.As<IEngineProcess>().SingleInstance();
builder.RegisterInstance(_streamingRoot);
builder.RegisterInstance(_tapeStorage);
builder.RegisterInstance(new TapeStorageInitilization(new[] {_tapeStorage})).As<IEngineProcess>();
builder.Update(componentRegistry);
}
示例7: Register
public override void Register(ContainerBuilder builder) {
var testVirtualPathProvider = new StylesheetBindingStrategyTests.TestVirtualPathProvider();
builder.RegisterInstance(new ShellSettings { Name = "Default" });
_folders = new ExtensionManagerTests.StubFolders();
_packagesInRepository = new ModuleStepTest.StubPackagingSourceManager();
_packageManager = new ModuleStepTest.StubPackageManager();
builder.RegisterInstance(_folders).As<IExtensionFolders>();
builder.RegisterType<RecipeExecutionLogger>().AsSelf();
builder.RegisterType<ExtensionManager>().As<IExtensionManager>();
builder.RegisterType<FeatureManager>().As<IFeatureManager>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
builder.RegisterType<StubAsyncTokenProvider>().As<IAsyncTokenProvider>();
builder.RegisterType<ShellDescriptorManager>().As<IShellDescriptorManager>().SingleInstance();
builder.RegisterType<ModuleStepTest.StubDataMigrationManager>().As<IDataMigrationManager>();
builder.RegisterInstance(_packagesInRepository).As<IPackagingSourceManager>();
builder.RegisterInstance(_packageManager).As<IPackageManager>();
builder.RegisterType<ShellStateManager>().As<IShellStateManager>().SingleInstance();
builder.RegisterInstance(testVirtualPathProvider).As<IVirtualPathProvider>();
builder.RegisterType<StubEventBus>().As<IEventBus>().SingleInstance();
builder.RegisterType<ThemeService>().As<IThemeService>();
builder.RegisterType<StubOrchardServices>().As<IOrchardServices>();
builder.RegisterType<StubSiteThemeService>().As<ISiteThemeService>();
builder.RegisterType<ThemeStep>();
builder.RegisterSource(new EventsRegistrationSource());
}
示例8: SetUpRootScope
public void SetUpRootScope()
{
var builder = new ContainerBuilder();
// this is needed to allow the Mediator to resolve contravariant handlers (not enabled by default in Autofac)
builder.RegisterSource(new ContravariantRegistrationSource());
builder.RegisterAssemblyTypes(typeof (IMediator).Assembly, GetType().Assembly)
.AsClosedTypesOf(typeof (IRequestHandler<,>))
.AsImplementedInterfaces();
builder.RegisterType<Mediator>().AsImplementedInterfaces().InstancePerLifetimeScope();
// to allow ShortBus to resolve lifetime-scoped dependencies properly,
// we really can't use the default approach of setting the static (global) dependency resolver,
// since that resolves instances from the root scope passed into it, rather than
// the current lifetime scope at the time of resolution.
// Resolving from the root scope can cause resource leaks, or in the case of components with a
// specific scope affinity (AutofacWebRequest, for example) it would fail outright,
// since that scope doesn't exist at the root level.
builder.RegisterType<AutofacDependencyResolver>()
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
RootScope = builder.Build();
RootScope.ComponentRegistry.Sources.ToList()
.ForEach(s => Console.WriteLine("{0} ({1})", s.GetType().Name, s));
}
示例9: BuildAutofacContainer
private static IContainer BuildAutofacContainer(IAppBuilder app)
{
var builder = new ContainerBuilder();
// Register your MVC controllers.
builder.RegisterControllers(typeof(MvcApplication).Assembly);
// OPTIONAL: Register model binders that require DI.
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
// OPTIONAL: Register web abstractions like HttpContextBase.
builder.RegisterModule<AutofacWebTypesModule>();
// OPTIONAL: Enable property injection in view pages.
builder.RegisterSource(new ViewRegistrationSource());
// OPTIONAL: Enable property injection into action filters.
builder.RegisterFilterProvider();
//Register Dependencies
RegisterIdentityParts(app, builder);
RegisterImageParts(app, builder);
RegisterContentParts(app, builder);
return builder.Build();
}
示例10: TestGeneralizedProperties
public void TestGeneralizedProperties()
{
var kernel = new ContainerBuilder();
kernel.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
var builder = kernel.UseDatenMeisterDotNet(new IntegrationSettings { PathToXmiFiles = "Xmi" });
using (var scope = builder.BeginLifetimeScope())
{
var classifierMethods = scope.Resolve<ClassifierMethods>();
classifierMethods.Legacy = false;
var dataLayers = scope.Resolve<DataLayers>();
var dataLayerLogic = scope.Resolve<DataLayerLogic>();
// Gets the logic
var uml = dataLayerLogic.Get<_UML>(dataLayers.Uml);
var feature = uml.Classification.__Feature;
var properties = classifierMethods.GetPropertiesOfClassifier(feature).ToList();
Assert.That(properties.Contains(_UML._Classification._Feature.isStatic), Is.True,
"isStatic");
Assert.That(properties.Contains(_UML._Classification._RedefinableElement.isLeaf), Is.True,
"isLeaf (Parent)");
Assert.That(properties.Contains(_UML._CommonStructure._NamedElement.name), Is.True,
"name (Parent of Parent)");
}
}
示例11: Load
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<PaymentService>().As<IPaymentService>();
builder.RegisterType<FormFactory>().As<IFormFactory>();
builder.RegisterType<MainWindow>().AsSelf().SingleInstance();
builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
}
示例12: RegisterTypes
public static void RegisterTypes()
{
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(ContainerConfig).Assembly);
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
builder.RegisterModule<AutofacWebTypesModule>();
builder.RegisterSource(new ViewRegistrationSource());
builder.RegisterFilterProvider();
builder.Register(x => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
builder.RegisterType<WorkaroundEmailService>().As<IEmailService>().SingleInstance();
RegisterServices(builder);
RegisterBackgroundTasks(builder);
builder.RegisterType<AuctioneerDbContext>().InstancePerRequest();
builder.RegisterType<BreadcrumbBuilder>().As<IBreadcrumbBuilder>().InstancePerDependency();
builder.RegisterType<AuthenticationManager>().As<IAuthenticationManager>().InstancePerRequest();
builder.RegisterType<EmailUserNotifier>().As<IUserNotifier>().SingleInstance();
builder.RegisterType<LanguageService>().As<ILanguageService>().SingleInstance();
builder.RegisterType<AuctionService>().As<IAuctionService>().InstancePerRequest().WithParameters(new Parameter[]
{
new NamedParameter("photoDirectoryPath", HostingEnvironment.MapPath("~/Content/UserContent/Auctions/Photos")),
new NamedParameter("thumbnailDirectoryPath", HostingEnvironment.MapPath("~/Content/UserContent/Auctions/Thumbnails"))
});
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
示例13: ConfigureContainer
public static IContainer ConfigureContainer()
{
var _builder = new ContainerBuilder();
//Call into our data project and let it register it's common services into the same builder
TypeScript.Demo.Data.AutofacConfig.RegisterCommonServices(_builder);
//This code is fairly stock code demonstrating how to tightly integrate Autofac with MVC and WebAPI
_builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
_builder.RegisterModelBinders(Assembly.GetExecutingAssembly()).PropertiesAutowired();
_builder.RegisterModelBinderProvider();
_builder.RegisterModule(new AutofacWebTypesModule());
_builder.RegisterSource(new ViewRegistrationSource());
_builder.RegisterFilterProvider();
_builder.RegisterWebApiModelBinders(Assembly.GetExecutingAssembly()).PropertiesAutowired();
_builder.RegisterApiControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
var _container = _builder.Build();
// Tell ASP.NET MVC to use Autofac to resolve components
DependencyResolver.SetResolver(new AutofacDependencyResolver(_container));
// Create the depenedency resolver for web API
var resolver = new AutofacWebApiDependencyResolver(_container);
// Configure Web API with the dependency resolver.
GlobalConfiguration.Configuration.DependencyResolver = resolver;
return _container;
}
示例14: ConfigureContainer
public static void ConfigureContainer()
{
var builder = new ContainerBuilder();
// Register dependencies in controllers
builder.RegisterControllers(typeof(AutofacConfig).Assembly);
// Register dependencies in filter attributes
builder.RegisterFilterProvider();
// Register dependencies in custom views
builder.RegisterSource(new ViewRegistrationSource());
// Register our Data dependencies
builder.RegisterModule(new Application.Composition.CoreModule());
builder.RegisterModule(new Application.Composition.ApplicationModule());
builder.RegisterModule(new Application.Composition.MessagingModule());
builder.RegisterModule(new PersistenceModule()
{
ConnectionStringOrName = "name=ClaimConnectionString"
});
var config = GlobalConfiguration.Configuration;
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterWebApiFilterProvider(config);
var container = builder.Build();
// Set MVC DI resolver to use our Autofac container
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
示例15: RegisterServices
protected void RegisterServices()
{
var tenantIdStrategy = new RouteDataItemTenantIdentificationStrategy("tenant");
var builder = new ContainerBuilder();
// Register your MVC controllers.
builder.RegisterControllers(typeof(MvcApplication).Assembly);
// OPTIONAL: Register model binders that require DI.
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
// OPTIONAL: Register web abstractions like HttpContextBase.
builder.RegisterModule<AutofacWebTypesModule>();
// OPTIONAL: Enable property injection in view pages.
builder.RegisterSource(new ViewRegistrationSource());
// OPTIONAL: Enable property injection into action filters.
builder.RegisterFilterProvider();
// Create the multitenant container and the tenant overrides.
var mtc = new MultitenantContainer(tenantIdStrategy, builder.Build());
AddTenant(mtc, "a");
AddTenant(mtc, "b");
DependencyResolver.SetResolver(new AutofacDependencyResolver(mtc));
}