This commit is contained in:
Ali MJ Al-Nasrawy 2021-06-10 22:36:52 +03:00
parent 812269d656
commit 6cb1e32431
1 changed files with 10 additions and 15 deletions

View File

@ -424,7 +424,6 @@ where
// complete scope pipeline creation
*self.factory_ref.borrow_mut() = Some(ScopeFactory {
app_data: self.app_data.take().map(Rc::new),
default,
services: cfg
.into_services()
@ -446,18 +445,25 @@ where
Some(self.guards)
};
let app_data = self.app_data.take().map(Rc::new);
let endpoint = apply_fn_factory(self.endpoint, move |mut req: ServiceRequest, srv| {
if let Some(ref data) = app_data {
req.add_data_container(Rc::clone(data));
}
srv.call(req)
});
// register final service
config.register_service(
ResourceDef::root_prefix(&self.rdef),
guards,
self.endpoint,
endpoint,
Some(Rc::new(rmap)),
)
}
}
pub struct ScopeFactory {
app_data: Option<Rc<Extensions>>,
services: Rc<[(ResourceDef, HttpNewService, RefCell<Option<Guards>>)]>,
default: Rc<HttpNewService>,
}
@ -485,8 +491,6 @@ impl ServiceFactory<ServiceRequest> for ScopeFactory {
}
}));
let app_data = self.app_data.clone();
Box::pin(async move {
let default = default_fut.await?;
@ -502,17 +506,12 @@ impl ServiceFactory<ServiceRequest> for ScopeFactory {
})
.finish();
Ok(ScopeService {
app_data,
router,
default,
})
Ok(ScopeService { router, default })
})
}
}
pub struct ScopeService {
app_data: Option<Rc<Extensions>>,
router: Router<HttpService, Vec<Box<dyn Guard>>>,
default: HttpService,
}
@ -536,10 +535,6 @@ impl Service<ServiceRequest> for ScopeService {
true
});
if let Some(ref app_data) = self.app_data {
req.add_data_container(app_data.clone());
}
if let Some((srv, _info)) = res {
srv.call(req)
} else {