Skip to content

Questions regarding scope and initialization #8

@ThisNoName

Description

@ThisNoName

In previous version, I have to specify HttpContextScoped. I can still do it in 3.1 but if this is done in a Registry in a library, it has to reference StructureMap.Web, seems defeat the purpose of that separation. Is this no longer necessary because I read something about container per request?

For<IDatabase>().Use(() => new Database("DefaultDb"))
    .LifecycleIs<HttpContextLifecycle>();

Another thing, one of the mediator interface (MediatR) I use take input parameter.

 public class Mediator : IMediator    {
      public Mediator(ServiceLocatorProvider serviceLocatorProvider)   {
            _serviceLocatorProvider = serviceLocatorProvider;
       }

If I left everything default, when injected, it will complain no parameter-less constructor. Somehow through trial and error, I manage to get it work by changing the IoC initialize to the following. But I have no idea if it's the right way. Can someone help take a look?

    public static IContainer Initialize()
    {
        Container container = new Container(x => x.AddRegistry<DefaultRegistry>());

        container.Configure(cfg => cfg.For<ServiceLocatorProvider>()
            .Use(new ServiceLocatorProvider(() => new StructureMapDependencyScope(container))));

        return container;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions