codingdir logo sitemap sitemap |
Home
PHP
C#
C++
ANDROID
JAVA
JAVASCRIPT
PYTHON

How to register same class twice with different dependencies


By : , Category : c#

I'm not sure if this is closer to what you're asking for, but, you can use ServiceOverride.ForKey to specify which parameters map to which names:

Component.For<Bar>().ImplementedBy<Bar>().
    DependsOn(ServiceOverride.ForKey("fooAbc").Eq("abc")).
    DependsOn(ServiceOverride.ForKey("foo123").Eq("123"))
);

Alternatively, not a direct answer, but an option you have is to resolve an IEnumerable<IFoo>. This is a good option if you actually have an arbitrary number of IFoo to resolve.

If you change the definition of Bar to accept an IEnumerable

public class Bar
{
    private readonly IEnumerable<IFoo> _foos;

    public Bar(IEnumerable<IFoo> foos)
    {
        _foos = foos;
    }
}

Then to register and resolve. You need to add the Resolve before you do the registrations.

var container = new WindsorContainer();

container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel, true));

container.Register(
    Component.For<IFoo>().Instance(new Foo("abc")).Named("abc"),
    Component.For<IFoo>().Instance(new Foo("123")).Named("123"),
    Component.For<Bar>().ImplementedBy<Bar>());
ReLated :

The ConnectImplementationsToTypesClosing method of StructureMap connects implementations to open generic types.

Hence:

scan.ConnectImplementationsToTypesClosing(typeof(IHandle<>));

will register all implementations that close the open generic type IHandle<>

The equivalent in AutoFac would be:

builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies())
   .AsClosedTypesOf(typeof(IHandle<>))
   .AsImplementedInterfaces();

See the following links for more information

  1. AutoFac Scanning
  2. AutoFac Open Generics

But I couldn't find any of such specification of how many registers does the cpu contain

Just look for "ia32 programming model" or "amd64 programming model".

I couldn't figure out how many of these are used by c storage classes.

That is implementation dependent. A compiler can even ignore that. Some of them use automatic register mapping if invoked with a high level of optimization, regardless of the way the variable has been declared.

For example: the programming model for user-mode applications on IA32 is composed of the registers EAX, EBX, ECX, EDX, ESI, EDI, EBP, ESP and EIP. EAX and EDX are used as accumulators, they are implicit operands for some instructions (MUL, DIV) and they hold the return value of a function. EBP and ESP are reserved for stack and frame management. EIP is the instruction pointer. So this leaves us with EBX, ECX, EDI and ESI for register mapping. Depending upon the code generated, one or more of these registers may be needed, so reducing even more the number of available registers for mapping variables.

Automatic variables like $@ are only meaningful in the recipe: make computes them after it parsed the dependency line completely. While interpreting the dependency $@ is set to nothing. You have to spell it out explicitly:

$(CXXCPP): $(CXXTEST)
    cxxtestgen ... (this line may use $@, $^, etc)

I see this linkOverview Collection View

If the cell class was written in code, the registration is performed using the registerClass: method of UICollectionView. For example: [self.myCollectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"MYCELL"]; In the event that the cell is contained within an Interface Builder NIB file, the registerNib: method is used instead.

So your collection cell create with nib, you should register with nib. If your cell written totally in code you will need register with class.

Hope this help.

Comments


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © codingdir.com All Rights Reserved .