Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Nicholas Blumhardt
    @nblumhardt
    Good luck! :-)
    brsmith080
    @brsmith080
    @Firedragonweb honestly, Im not entirely sure - seems to be some fear of memory leak problems
    and maybe some confusion of what the disposable pattern's purpose is
    someone said something that made me think they expect dispose to do the GC's job in terms of cleanup for a given thing
    but, Im hoping I just misunderstood him
    @nblumhardt yeah, that's been my argument so far too, and autofac doing a good job of cleaning up after itself is one of the features that brought me to it forever ago
    Jerome Haltom
    @wasabii
    There anyway to use RegisterAssemblyTypes, or other batch registration, to register open generics, when the type is unknown at compile time? AsClosedTypes requires the type to be specififed. I need to derive it from the scanned type.
    Sami Al Khatib
    @alsami

    There anyway to use RegisterAssemblyTypes, or other batch registration, to register open generics, when the type is unknown at compile time? AsClosedTypes requires the type to be specififed. I need to derive it from the scanned type.

    You want to find generic-types in assemblies and register all implementations without knowing the generic types?

    Sami Al Khatib
    @alsami

    There anyway to use RegisterAssemblyTypes, or other batch registration, to register open generics, when the type is unknown at compile time? AsClosedTypes requires the type to be specififed. I need to derive it from the scanned type.

    You want to find generic-types in assemblies and register all implementations without knowing the generic types?

    If I understood your requirement correctly, I made a small example on how it'd be possible to do that with Autofac.
    https://github.com/alsami/Autofac.GenericTypes.Unknown.git

    Keep in mind that there are a few edge-cases where this wouldn't work without some more work. For instance when generic is implemented through a base-class and what not.

    Sami Al Khatib
    @alsami
    Maybe @alexmg , @tillig or @nblumhardt have a better idea.
    Jerome Haltom
    @wasabii
    Metadata question: by strongly typed interface. There any code floating around for this? I'd imagine being able to just resolve Lazy<T, Interface>() and have castle or something generate the interface implementation.
    Blair Conrad
    @blairconrad
    Hi, @wasabii, what's the goal? For testing? I'd expect not for production…
    For testing, I'd recommend Autofac.Extras.FakeItEasy (although I understand there are also flavours of this for some of those other mocking frameworks :grin:). Or Autofac.Extras.DynamicProxy can be used in other contexts, I imagine.
    Caveat: I've never used Autofac.Extras.DynamicProxy, and only used Autofac.Extras.FakeItEasy while fixing issues, never in earnest.
    Jerome Haltom
    @wasabii
    Not testing.
    Blair Conrad
    @blairconrad
    Probably DynamicProxy, then…
    MBQNIAZ
    @MBQNIAZ
    could autofac be implemented in wpf mvvm .net core project as it is implemented in asp.net core projects?
    Sami Al Khatib
    @alsami
    @MBQNIAZ What do you exactly mean with "as it is implemented in asp.net core"? The hosting-mechanismns?
    Alex Meyer-Gleaves
    @alexmg
    nawfalhasan
    @nawfalhasan
    Hi all. Is there a way I can check if a type (the interface) is registered with Autofac already?
    nawfalhasan
    @nawfalhasan

    I am trying to resolve a type at runtime. Basically the type's constructor accepts both (autofac registered) dependencies as well as other values. This is how my code looks like:

    MVVMContextCompositionRootEx.ViewModelCreate += (s, e) =>
    {
        using (var scope = rootContainer.BeginLifetimeScope(
            containerBuilder => containerBuilder.RegisterType(e.RuntimeViewModelType).As(e.ViewModelType)))
        {
            e.ViewModel = scope.Resolve(e.ViewModelType, e.Parameters.Select(x => new NamedParameter(x.Item1, x.Item2)));
        }
    };

    Basically, the constructor arguments are got from e.Parameters but there I want to filter out parameters which are dependencies already registered in autofac.

    Michael Wegge
    @Firedragonweb
    How about the IfNotAlreadyRegistered extension method :)?
    *
    IfNotRegistered, sorry, I was typing
    nawfalhasan
    @nawfalhasan
    @Firedragonweb thanks, let me take a look
    nawfalhasan
    @nawfalhasan
    I solved it using rootContainer.IsRegistered method.
    Stefan Ossendorf
    @StefanOssendorf
    Hello everyone. Is there any ETA on v5 release?
    Tyler S Lemke
    @tylerslemke
    Hey Guys. Does anyone know of a good blog on updating Autofac to use .Net Core 3.0? We are utilizing an in house core library to control Autofac and the current documentation doesn't answer all of the questions that we have.
    Stefan Ossendorf
    @StefanOssendorf
    I think there changed nothing within .net core 3.0 only with asp.net core 3.0 (see https://autofaccn.readthedocs.io/en/latest/integration/aspnetcore.html#asp-net-core-3-0-and-generic-hosting)
    Sami Al Khatib
    @alsami

    Hey Guys. Does anyone know of a good blog on updating Autofac to use .Net Core 3.0? We are utilizing an in house core library to control Autofac and the current documentation doesn't answer all of the questions that we have.

    I don't know any but I'd be glad to help. Basically there is not much difference when speaking about ASP.NET Core 3 vs 2.x
    These links pretty much show the difference:
    https://autofac.readthedocs.io/en/latest/integration/aspnetcore.html#asp-net-core-1-1-2-2
    https://autofac.readthedocs.io/en/latest/integration/aspnetcore.html#asp-net-core-3-0-and-generic-hosting

    I think there changed nothing within .net core 3.0 only with asp.net core 3.0 (see https://autofaccn.readthedocs.io/en/latest/integration/aspnetcore.html#asp-net-core-3-0-and-generic-hosting)

    There is no actual ETA but we are working on it

    nawfalhasan
    @nawfalhasan

    Is there a way to tell Autofac to dispose the scope (and the dependencies it resolved) associated with an object, if all I got is the concrete instance?

    For e.g. I got this:

     var myService = scope.Resolve(....
    
     // later at some point,
     rootContainer.DisposeOff(myService) // <-- this should dispose the lifetime scope of myService, i.e. dispose myService, along with its other dependencies.
    Alistair Evans
    @alistairjevans
    I've posted an answer on SO.
    nawfalhasan
    @nawfalhasan
    @alistairjevans thank you.
    Michael Wegge
    @Firedragonweb
    does anyone know if it's possible to define a registration as the default registration for a service regardless of the registration order? I tried .WithMetadata( "__RegistrationOrder", -1), but that throws because the "__RegistrationOrder" metadata has already been added and .WithMetadata does not overwrite
    Alistair Evans
    @alistairjevans
    Take a look at this (closed) issue: autofac/Autofac#712
    Michael Wegge
    @Firedragonweb
    thank you!
    avilv
    @avilv
    any idea why Owned<T> different than Func<Owner<T>>? it seems just trying to resolve Owned<T> wont create a new lifetimescope
    Stefan Ossendorf
    @StefanOssendorf
    You are telling autofac with Owned<T> that it's not responsible for disposing so why should it create a lifetimescop for the object?
    Michael Wegge
    @Firedragonweb
    Because Owned<T> means "T wrapped in its own lifetime scope that you are responsible for disposing" according to the docs
    I would also expect an Owned<T> dependency to come in its own lifetimescope
    John Zabroski
    @jzabroski

    any idea why Owned<T> different than Func<Owner<T>>? it seems just trying to resolve Owned<T> wont create a new lifetimescope

    I think you mean Func<Owned<T>> - Func is just scaffolding to scrap boilerplate for creating a factory that has a ILifetimeScope. This is because the signature for a Factory Method pattern is:

    public interface IFactory<T>
    {
        T Create(object context);
    }

    Which can be simplified to just:

    public interface IFactory<T>
    {
        T Create();
    }

    Which can be, if you squint your eyes, converted to just:

    Func<T> TFactory => _lifetimeScope.Resolve<T>();

    and so, when you call TFactory(); you're effectively calling new YourFactory<T>().Create();

    Also, note the object context parameter can be a higher-order parameter by passing it into the object's constructor instead of as a parameter, so that it can be recursively called on any method the factory exposes. But Factories in general just expose a single method, Create();.
    Guy Lepine
    @delepster
    Hi, I'm getting this obscure exception when trying to build the container:
    This exception was originally thrown at this call stack: Autofac.Util.TypeExtensions.IsCompatibleWithGenericParameterConstraints(System.Type, System.Type[]) Autofac.Features.OpenGenerics.OpenGenericServiceBinder.TryBindServiceType(Autofac.Core.Service, System.Collections.Generic.IEnumerable<Autofac.Core.Service>, System.Type, out System.Type, out Autofac.Core.Service[]) Autofac.Features.OpenGenerics.OpenGenericRegistrationSource.RegistrationsFor(Autofac.Core.Service, System.Func<Autofac.Core.Service, System.Collections.Generic.IEnumerable<Autofac.Core.IComponentRegistration>>) Autofac.Core.Registration.ComponentRegistry.GetInitializedServiceInfo(Autofac.Core.Service) Autofac.Core.Registration.ComponentRegistry.IsRegistered(Autofac.Core.Service) Autofac.RegistrationExtensions.IfNotRegistered.AnonymousMethod__0(Autofac.Core.IComponentRegistry) Autofac.RegistrationExtensions.OnlyIf.AnonymousMethod__0(Autofac.Core.IComponentRegistry) Autofac.ContainerBuilder.Build(Autofac.Core.IComponentRegistry, bool) Autofac.Module.Configure(Autofac.Core.IComponentRegistry) Autofac.ContainerBuilder.Build(Autofac.Core.IComponentRegistry, bool)
      HResult=0x80131508
      Message=Index was outside the bounds of the array.
    any ideas?
    Nicholas Blumhardt
    @nblumhardt
    @avilv how are you determining whether or not a new lifetime scope is created? Resolve<Owned<T>>() or depending on Owned<T> will create a new scope. Check out https://github.com/autofac/Autofac/blob/develop/src/Autofac/Features/OwnedInstances/OwnedInstanceRegistrationSource.cs#L66
    Wrapping it in Func<> will create a new scope for each invocation of the function, so behavior differs between these two, but both end up creating new scopes by way of Owned<T>. HTH!