What does AsSelf do in autofac? [duplicate]

Typically you would want to inject interfaces, rather than implementations into your classes. But let’s assume you have: interface IFooService { } class FooService { } Registering builder.RegisterType<FooService>() allows you to inject FooService, but you can’t inject IFooService, even if FooService implements it. This is equivalent to builder.RegisterType<FooService>().AsSelf(). Registering builder.RegisterType<FooService>().As<IFooService>() allows you to inject IFooService, … Read more

How does Spring achieve IOC with autowiring?

First, and most important – all Spring beans are managed – they “live” inside a container, called “application context”. Second, each application has an entry point to that context. Web applications have a Servlet, JSF uses a el-resolver, etc. Also, there is a place where the application context is bootstrapped and all beans – autowired. … Read more

IoC in class library. Where to bootstrap

I know that an answer has been chosen, however I think a part of Unity is being overlooked. Since this was a specific Unity question I thought I point out the UnityContainerExtension base class that implements the IUnityContainerExtensionConfigurator. This is there for API library to extend to make it easy for the entry-point application who … Read more

How to create a child scope from the parent with default dependency injection in .NET Core?

Use IServiceProvider.CreateScope() method to create a local scope: var services = new ServiceCollection(); services.AddScoped<ExampleService>(); var globalProvider = services.BuildServiceProvider(); using (var scope = globalProvider.CreateScope()) { var localScoped = scope.ServiceProvider.GetService<ExampleService>(); var globalScoped = globalProvider.GetService<ExampleService>(); } It can be easily tested: using (var scope = globalProvider.CreateScope()) { var localScopedV1 = scope.ServiceProvider.GetService<ExampleService>(); var localScopedV2 = scope.ServiceProvider.GetService<ExampleService>(); Assert.Equal(localScopedV1, localScopedV2); var … Read more

Dependency Injection – new instance required in several of a classes methods

Most of the answers here so far suggest that you change the injected dependency type to some sort of Abstract Factory (a Func<T> is also an Abstract Factory) to address the issue. However, if you do that it would be a leaky abstraction because you would let the knowledge of a particular implementation determine the … Read more

MVVM and IOC: Handling View Model’s Class Invariants

I’m not quite sure what the issue is, so I’ll use a simple and contrived example. Let’s say you have a CustomerListViewModel which lists a summary of each customer. When you select a customer, you want to display a CustomerDetailViewModel. This could take either a customer ID, or an ICustomer type which is populated previously … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)